简体   繁体   English

检测“返回顶部”按钮上的滚动到底部像素

[英]Detecting scroll to bottom pixel on back to top button

I have this solution for back to top button. 我有此解决方案的返回页首按钮。

HTML: 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: CSS:

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

JS: JS:

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

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

It's working. 工作正常 But ı want when scroll to bottom 200px, get scroll button to me. 但我想滚动到底部200px时,得到滚动按钮给我。 How can I set this option? 如何设置此选项?

Try this code : 试试这个代码:

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

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

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