gpt4 book ai didi

jquery - 当 div 滚动到 | 时触发函数jQuery

转载 作者:行者123 更新时间:2023-12-01 00:25:38 25 4
gpt4 key购买 nike

是否有可能,如果滚动到一个 div,它应该执行一个函数,例如:

alt text

是吗?没有?

最佳答案

$(window).scroll(function () { 
if ($(window).scrollTop() <= $("div#14").position().top && $(window).scrollTop() + $(window).height() >= $("div#14").position().top) {
if ($("div#14").position().top + $("div#14").height() <= $(window).scrollTop() + $(window).height()) {
do_something();
}
}
});

编辑抱歉,我把“">=”和“<=”写错了。

在这里观看:http://jsfiddle.net/cBdhk/4/

编辑 2 我更新了链接,但忘记更新代码。

关于jquery - 当 div 滚动到 | 时触发函数jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3968447/

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