用jquery实现动画跳到顶部和底部(这个比较简单)
当点击顶部按钮的时候,执行方法,scrollTop属性获取选中标签距滚动条的距离,当点击底部标签时候,执行方法,其中offset()获取匹配元素在当前视口的相对偏移
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <title>UntitledPage</title> <scripttype="text/javascript"src=jquery-1.8.0.js></script> <script> $(document).ready(function(){ //当点击顶部按钮的时候,执行方法,scrollTop属性获取选中标签距滚动条的距离。 $('#top').click(function(){ $('html').animate( {scrollTop:'0px'},1000 ); }); //当点击底部标签时候,执行方法,其中offset()获取匹配元素在当前视口的相对偏移,返回的是一个对象,有两个属性top,left //animate,的第二个属性当然我们也可以设置'slow','normal'或'fast' $('#foot').click(function(){ $('html').animate( {scrollTop:$('span').offset().top},1000 ); }); }); </script> </head> <body> <br/><br/><br/><br/><br/> <ahref="#"id="foot">底部</a> <br/><br/><br/><br/><br/> <br/><br/><br/><br/><br/> <ahref="#"id="top">顶部</a> <br/><br/><br/><br/><br/> <span></span> </body> </html>