JS 回到頂端 back to top


CSS:
.backtoTop2{
    height: 40px;
    width: 50px;
    position: fixed;     
    padding-top: 8px;
    right: 100px;
    z-index: 9999;
    background: red;
    cursor: pointer;
    text-align: center;
}

JS:
$(document).ready(function(){
    $(window).scroll( function() {                    // change scroll event
        var height = $(window).height(),          //get window height
              top = $(document).scrollTop();       //get scroll top
        if(top > height ){                                    //more than height to show
            $("#backToTop2").fadeIn(300).css({
                top: height-80
            });
        }
        if(top < height ){                                   //less than height to disappear
            $("#backToTop2").fadeOut(200);
        }
    });
    /*back to top click*/
    $('#backToTop2').click(function(){
        $('html, body').animate({                     // Animation effects --> move
            scrollTop: 0
        }, 500);
    });
});
  
HTML:
<divid="backToTop2"class="backtoTop2"></div>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM