-
需求:假設我有一個名為box的盒子,當內容撐大時會出現滾動條,每次我事件觸發時,滾動條都在底部。
<div class="box">內容</div>
<script>
var el_height = $('.box').scrollHeight ===> 獲得滾動條的高度
$('.box').scollTop(el_height) ===> 設置滾動條的位置,滾動到底部
</script>
-
需求:如何判斷滾動條是否滑到底部?
//scrollHeight 整個滾動區域的長度
$('.box')[0].scrollHeight
//scrollTop 滾動條距離上邊的距離 clientHeight 滾動條自身的長度
$('.box').scrollTop()+$('.box')[0].clientHeight
// 當整個滾動區域長度scrollHeight === scrollTop + clientHeight的值那么滾動條就已經到底了
-
需求:滾動條滾動的事件?
onscroll