码迷,mamicode.com
首页 > Web开发 > 详细

最简单的用jquery实现动画的跳到顶部和底部

时间:2016-03-17 12:16:06      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="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 />
  <a href="#" id="foot">底部</a>
  <br /> <br /> <br /> <br /> <br />
  <br /> <br /> <br /> <br /> <br />
 
<a href="#" id="top">顶部</a>
  <br /> <br /> <br /> <br /> <br />
  <span></span>
</body>
</html>

 

最简单的用jquery实现动画的跳到顶部和底部

标签:

原文地址:http://www.cnblogs.com/lr393993507/p/5286593.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!