div容器設置overflow:hidden隱藏滾動條后,容器中內容超出設定高度則不可見。
通過js方法,實現div垂直滾動條滾動到底部,以顯示最新的內容。
var clientHeight = $('div#box').height(); var offsetHeight = $('div#box').get(0).scrollHeight; console.log('窗口高度:' + $('div#box').height()); console.log('內容高度:' + $('div#box').get(0).scrollHeight); if (offsetHeight > clientHeight) { $('div#box').scrollTop(offsetHeight - clientHeight); }.height() 取得容器的可見高度.scrollHeight 取得容器DOM的內容高度
.scrollTop 設置y軸滾動位置。0則不滾動,內容-可見高度則滾動到最底部
新聞熱點
疑難解答