Home > Web Front-end > JS Tutorial > body text

jquery 跳到顶部和底部动画2句代码简单实现_jquery

WBOY
Release: 2016-05-16 17:28:33
Original
1034 people have browsed it
复制代码 代码如下:




Untitled Page

<script> <BR>$(document).ready(function () { <BR>//当点击顶部按钮的时候,执行方法,scrollTop属性获取选中标签距滚动条的距离。 <BR>$('#top').click(function () { <BR>$('html').animate( <BR>{ scrollTop: '0px' }, 1000 <BR>); <BR>}); <BR>//当点击底部标签时候,执行方法,其中offset()获取匹配元素在当前视口的相对偏移,返回的是一个对象,有两个属性top,left <BR>//animate,的第二个属性当然我们也可以设置'slow','normal'或'fast' <BR>$('#foot').click(function () { <BR>$('html').animate( <BR>{scrollTop:$('span').offset().top},1000 <BR>); <BR>}); <BR>}); <BR></script>








底部













顶部









Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!