gpt4 book ai didi

javascript - 我希望当用户滚动到页面底部附近时创建一个静态菜单

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

使用Javascript,最好是Jquery,我希望能够在用户处于特定页面高度时触发div的可见性。纽约时报有一个这样的例子,当你滚动到一个故事的底部时,一个 slider 会弹出另一个新闻故事,如果你向上滚动, slider 就会消失。

最佳答案

我认为你想要的方法是:

$(document).scroll()    // event triggered whenever the page is scrolled
$(document).height() // gets the height of the entire page
$(window).height() // gets the height of the current window
$(document).scrollTop() // gets the top position currently visible

使用这些,您可以编写一个方法,在窗口距离底部 100 像素时显示 div:

$(document).scroll(function() {
var scrollBottom = $(document).scrollTop() + $(window).height();
var height = $(document).height();
if (scrollBottom > height - 100)
$("div").show();
else
$("div").hide();
});

关于javascript - 我希望当用户滚动到页面底部附近时创建一个静态菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2785517/

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