网页返回顶端的JS代码
1 <script > 2 $(function(){ 3 $(window).bind("scroll", function(){ 4 var sh = $(document).scrollTop(); 5 if(isie6Fun()){ 6 var wh = $(window).height(); 7 var ssss= wh*0.8+sh; 8 $("#returntop").css("top",ssss+"px"); 9 } 10 if($("#returntop").is(":visible")){ 11 if(sh<260){ 12 $("#returntop").hide(); 13 } 14 } 15 if($("#returntop").is(":hidden")){ 16 if(sh>260){ 17 $("#returntop").show(); 18 } 19 } 20 }); 21 $("#returntop").click(function(){ 22 $(document).scrollTop(0); 23 }); 24 }); 25 function isie6Fun(){ 26 var userAgent = navigator.userAgent.toLowerCase(); 27 var browserId = userAgent.match(/(firefox|chrome|safari|opera|msie)/)[1]; 28 Var browserVersion = (userAgent.match(new RegExp('.+(?:version)[\/: ]([\\d.]+)')) || userAgent.match(new RegExp('(?:'+browserId+')[\/: ]([\\d.]+)')) || [0,'0'])[1]; 29 var isIe6 = (browserId + browserVersion == "msie6.0"); 30 return isIe6; 31 } 32 </script>
<a id="returntop" href="javascript:void(0)" style="display:none;" title="返回顶部"></a>