我想記錄用戶滾動包裝的程度。使用scrollTop檢測滾動
以下代碼不起作用。 我想知道我做錯了什麼,以及如何解決它。謝謝!
const content = document.getElementById('content')
const wrapper = document.getElementById('wrapper').addEventListener('scroll',() => {
console.log(content.scrollTop)
})
#wrapper {
background-color: red;
position: absolute;
top: 0;
left: 0;
width: 250px;
height: 250px;
overflow: auto;
}
#content {
position: absolute;
top: 0;
left: 0;
background-color: orange;
width: 50px;
height: 500px;
}
<div id="wrapper">
<div id="content"></div>
</div>
包裝是具有不滾動的內容,所以它是總是會變成零。 –
好的謝謝,多少包裝正在滾動? – Radex