【转】自定义置顶TOP按钮
1 <style type="text/css"> 2 #GoTop{ 3 width:40px; 4 height:40px; 5 background-color:#F59E1D; 6 position:fixed; 7 bottom:30px; 8 right:30px; 9 font-size:19pt; 10 text-align:center; 11 color:#FFF; 12 text-decoration:none; 13 } 14 </style> 15 16 <div> 17 <a id="GoTop" onclick="GoTopFunction()" href="javascript:void(0)">∧</a> 18 </div> 19 20 <script type="text/javascript"> 21 $(document).ready(function(){ 22 $("#GoTop").mouseenter( 23 function(){ 24 $("#GoTop").css("color","#FFF"); 25 $("#GoTop").css("background-color","#F3D117"); 26 $("#GoTop").css("text-decoration","none"); 27 } 28 ); 29 $("#GoTop").mouseleave( 30 function(){ 31 $("#GoTop").css("color","#FFF"); 32 $("#GoTop").css("background-color","#F59E1D"); 33 $("#GoTop").css("text-decoration","none"); 34 } 35 ); 36 }); 37 38 var sth; 39 function GoTopFunction(){ 40 FourLeafCloverZCVar=setInterval(GoTopFunctionEachScrollBy,10); 41 } 42 43 function GoTopFunctionEachScrollBy(eachHeight){ 44 45 //判断是否存在以下两个实例 46 if(document.documentElement && document.documentElement.scrollTop) 47 { 48 if(document.documentElement.scrollTop<=0){ 49 clearInterval(sth); 50 }else{ 51 window.scrollBy(0,-25); 52 } 53 }else{ 54 if(document.body.scrollTop<=0){ 55 clearInterval(sth); 56 }else{ 57 window.scrollBy(0,-25); 58 } 59 } 60 } 61 </script>
mark一下备用。
原文:http://www.th7.cn/web/js/201512/140040.shtml