jquery實現當頁面滾動超過一屏時顯示返回頂部按鈕


<!DOCTYPE html>  

<html>  

<head>  

<meta charset=utf-8" />  

<title>jquery實現當頁面滾動超過一屏時顯示返回頂部按鈕</title>  

<style>  

   #go_top{position:fixed; LEFT: 85%;bottom:50px;}  

</style>  

<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>  

<script>  

$(document).ready(function(){  

    $("#go_top").hide();  

   $(function () {  

      //檢測屏幕高度  

        var height=$(window).height();  

       //scroll() 方法為滾動事件  

       $(window).scroll(function(){  

           if ($(window).scrollTop()>height){  

              $("#go_top").fadeIn(500);  

         }else{  

              $("#go_top").fadeOut(500);  

                }  

        });  

        $("#go_top").click(function(){  

           $('body,html').animate({scrollTop:0},100);  

           return false;  

        });  

   });  

});  

</script>  

</head>  

<body>  

<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>  

<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>1<br/>  

<div id="go_top">  

   <img src="./img/top.png"/ alt="回到頂部圖片">  

</div>  

</body>  

</html>  


 

 


免責聲明!

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



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