Show “Back to top” link element using jQuery when you scroll down

后端 未结 2 1761
别跟我提以往
别跟我提以往 2021-01-31 17:52

I want to mimic behaviour with jQuery like you can see here: http://edo.webmaster.am/

Just look at the right bottom corner, scroll down a bit and you\'ll see the \"back

2条回答
  •  粉色の甜心
    2021-01-31 18:45

    You can monitor the current window scroll position and act accordingly. If you want the offset to be after a certain point (the below code will do any scrolling, even 1px) then just check that $(this).scrollTop() > n in the if statement, where n is the desired offset.

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

    $(window).scroll(function() {
        if ($(this).scrollTop()) {
            $('#toTop:hidden').stop(true, true).fadeIn();
        } else {
            $('#toTop').stop(true, true).fadeOut();
        }
    });
    

提交回复
热议问题