Get div to show/hide when scrolling for a “back to top” link

血红的双手。 提交于 2019-12-03 16:17:09

"So I would like the arrow-up div to visible(show("slow")) when not on top of the page"

I do that this way:

http://jsfiddle.net/wf_4/GubeC/

SCRIPT:

// fade in #back-top
$(function () {
    $(window).scroll(function () {
        if ($(this).scrollTop() > 300) {
            $('.back-top').fadeIn();
        } else {
            $('.back-top').fadeOut();
        }
    });

    // scroll body to 0px on click
    $('.back-top').click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 1600);
        return false;
    });
});

CSS

.back-top {
    width:25px;
    height:25px;
    background:#ff0000;
    position:fixed;
    bottom:68px;
    right:5px;
    display:none;
    opacity:0.8;
}

HTML

<div class="back-top" title="Top of Page"></div>       
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!