方法1:
<head> <style type="text/css"> #form_top{display:block; bottom:3px; right:3px; position:fixed;} .top_img{ background-image: url("img/top.png"); width: 40px; height:40px; cursor: pointer; } </style> </head> <body> <a id="_top"></a> <div id="form_top"><a href="#_top" title="回到顶部"><div class="top_img">回到顶部</div></a></div> </body>
方法2:
<body> <div id="scrollA" class="intr_tit"></div> <button id="ScrollToTop" class="btnimg Button2 WhiteButton Offscreen" type="button">返回<br>顶部</button> <script type="text/javascript"> $(document).ready(function(){ ScrollToTop.setup(); }); ScrollToTop.setup=function(){ //var a=$(window).height()/5; var a=$("#scrollA").offset().top; //alert(a.top); $(window).scroll(function(){ (window.innerWidth?window.pageYOffset:document.documentElement.scrollTop)>=a?$("#ScrollToTop").removeClass("Offscreen"):$("#ScrollToTop").addClass("Offscreen"); }); $("#ScrollToTop").click(function(){ $("html, body").animate({scrollTop:"0px"},400); return false; }); }; </script> </body>