繁体   English   中英

滚动到顶部脚本-位于顶部时div不会隐藏

[英]Scroll to top script - div won't hide when on top

我正在这个名为http://martindue.dk/mmd3x9x/的网站上工作,并且可以滚动到无法协作的顶级脚本。 我已经在许多其他网站上使用了该脚本,并且效果很好,但是在这个特定的网站上,即使我位于网站的顶部,div#to-top仍会重新出现,为什么不在顶部时它会正确淡出吗?

我的代码如下(在HTML的body-tag之后插入#to-top):

Java脚本

jQuery(document).ready(function() {
    $toTop = jQuery("#to-top");

    $toTop.hide();

    jQuery(window).scroll(function() {
        if(jQuery(this).scrollTop() != 0) {
            $toTop.fadeIn();  
        } else {
            $toTop.fadeOut();
        }    
    });

    $toTop.click(function() {
        jQuery("body, html").animate({ scrollTop : 0 }, 500);
        return false;
    });
});

的CSS

#to-top {
    background: url("img/to-top.png") center top no-repeat;
    background-size: 100%;
    width: 50px;
    height: 50px;
    position: fixed;
    bottom: 60px;
    right: 60px;
    cursor: pointer;
    /*display:none;*/
    /*opacity: 0.0;*/
}

我创建了这个小提琴,在这里工作正常: http : //jsfiddle.net/2Rubp/

我知道这不是js,但在这种情况下,您仅使用衰落,因此CSS可以解决问题:

#to-top {
background: url("img/to-top.png") center top no-repeat;
background-size: 100%;
width: 50px;
height: 50px;
position: fixed;
bottom: 60px;
right: 60px;
cursor: pointer;
**-webkit-transition: all 0.5s linear;** 
display: none;
opacity: 0.0;
}

注意:这是针对chrome的,请参阅此内容以了解跨浏览器的兼容性http://www.w3schools.com/css/css3_transitions.asp

暂无
暂无

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

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