Scroll to top JavaScript in HTML Website

后端 未结 4 1886
故里飘歌
故里飘歌 2021-01-26 13:17

I am trying to implement the scroll to top feature in my website: www.arrow-tvseries.com.

The \"button\" is seen on the website however it does not work properly, becaus

4条回答
  •  悲哀的现实
    2021-01-26 13:57

    You could do something like this:

    JSFiddle demo

    $(window).scroll(function() {
    
        // if you have scrolled down more than 200px
        if($(this).scrollTop() > 200) {
            $('#backtotop').fadeIn();
        } else {
            $('#backtotop').fadeOut();
        }
    });
    
    
    
    $('#backtotop').bind('click', function(e) {
        e.preventDefault();
        $('body,html').animate({scrollTop:0},800);
    });
    

提交回复
热议问题