JS方法实现div容器y轴滚动

    xiaoxiao2021-03-26  20

    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则不滚动,内容-可见高度则滚动到最底部

    转载请注明原文地址: https://ju.6miu.com/read-660221.html

    最新回复(0)