简体   繁体   English

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

[英]I am looking to create a static menu when a user scrolls near the bottom of the page

Using Javascript, Jquery preferably, I want to be able to trigger the visiblity of the div when a user is at a certain page height. 我希望使用Javascript(最好是Jquery),当用户处于某个页面高度时,我希望能够触发div的可见性。 NYtimes has an example of this when you scroll to the bottom of a story, a slider pops out with another news story, and goes away if you scroll up. 当您滚动到故事的底部时,NYtimes就是这样的一个例子,滑块会弹出另一个新闻故事,而当您向上滚动时,滑块就会消失。

I think the methods you want are: 我认为您想要的方法是:

$(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

Using these, you could write a method to show a div when the window is 100 pixels from the bottom: 使用这些,您可以编写一种方法来在窗口距底部100像素时显示div:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM