gpt4 book ai didi

javascript - 如何检查滚动条是否到达div的末尾?

转载 作者:行者123 更新时间:2023-11-28 11:36:29 26 4
gpt4 key购买 nike

function yHandler () {

var show = document.getElementById('show');
var contentHeight = show.offsetHeight;
var yOffset = show.pageYOffset;
var y = yOffset + show.innerHeight;

if(y >= contentHeight) {
alert("ok")
}
}
show.onscroll = yHandler;

如何检查滚动条是否到达div的末尾?

最佳答案

一些供您使用的代码:

var scroll = document.getElementById('scroll');
var content = document.getElementById('content');

scroll.onscroll = function(){
var total = scroll.scrollTop + scroll.clientHeight;

if(total == content.clientHeight)
alert('Reached bottom!');
}

http://jsfiddle.net/EY6qP/

关于javascript - 如何检查滚动条是否到达div的末尾?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19005348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com