正在检测从上到下按钮上的向下滚动像素

Detecting scroll to bottom pixel on back to top button

本文关键字:滚动 像素 检测 从上到下 按钮      更新时间:2023-09-26

我有这个返回顶部按钮的解决方案。

HTML:

<div id='toTop'>To The Top!</div><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

CSS:

#toTop {
    padding: 5px 3px;
    background: #000;
    color: #fff;
    position: fixed;
    bottom: 0;
    right: 5px;
    display: none;
}

JS:

$(window).scroll(function() {
    if ($(this).scrollTop()) {
        $('#toTop').fadeIn();
    } else {
        $('#toTop').fadeOut();
    }
});

http://jsfiddle.net/robert/fjXSq/

它起作用了。但是ı想要当滚动到底部200px时,让滚动按钮给我。我如何设置这个选项?

试试这个代码:

$(window).scroll(function() {
    if ($(this).scrollTop() > ($('html').height() - $(window).height() - 200)) {
        $('#toTop').fadeIn();
    } else {
        $('#toTop').fadeOut();
    }
});