smooth scroll to top

前端 未结 12 1156
眼角桃花
眼角桃花 2020-12-07 22:58

I\'ve bean searching for this for a few hours now and I have no solution. I want a smooth scroll to the top of the page. I already have smooth scrolling to separate anchors

12条回答
  •  醉梦人生
    2020-12-07 23:26

    Hmm comment function off for me,

    try this

    $(document).ready(function(){
        $("#top").hide();
        $(function toTop() {
            $(window).scroll(function () {
                if ($(this).scrollTop() > 100) {
                    $('#top').fadeIn();
                } else {
                    $('#top').fadeOut();
                }
            });
    
            $('#top').click(function () {
                $('body,html').animate({
                    scrollTop: 0
                }, 800);
                return false;
            });
        });         
                
                
        
        });
    #top {
      float:right;
      width:39px;
      margin-top:-35px; 
    }
    #top {
        transition: all 0.5s ease 0s;
        -moz-transition: all 0.5s ease 0s;
        -webkit-transition: all 0.5s ease 0s;
        -o-transition: all 0.5s ease 0s;
        opacity: 0.5;
        display:none;
        cursor: pointer;
    }
    #top:hover {
        opacity: 1;
    }
    
    

































































    no pic klick to top

提交回复
热议问题