使用了jQuery的animate函数。
代码如下:
<div id="full-top" style="position:fixed; left:50%; top:520px; margin-left:495px; z-index:100; text-align:center; cursor:pointer;"> <a><img src="//ww4.sinaimg.cn/large/a15b4afegy1fhb9dkt4iij201e01eglf" width="20" border="0" alt="返回顶部" title="返回顶部"></a> </div> <script type="text/javascript"> jQuery('#full-top').click(function(){ jQuery('html, body').animate({scrollTop:0}, 'slow'); return false; }); </script> <div id="full-btm" style="position:fixed; left:50%; top:550px; z-index:100; text-align:center; cursor:pointer;"> <a><img src="http://ww4.sinaimg.cn/large/a15b4afely1fhb9g7im1jj201e01emwx" width="20" border=0 alt="跳到底部" title="跳到底部"></a> </div> <script type="text/javascript"> jQuery('#full-btm').click(function(){ jQuery('html, body').animate({scrollTop:jQuery(document).height()}, 'slow'); return false; }); </script>