zoukankan      html  css  js  c++  java
  • 最简单的用jquery实现动画的跳到顶部和底部

    <!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>
  • 相关阅读:
    如何在Altium中下载并添加软件没有的苦文件【转】
    20121124
    变量作用域&函数作用域
    http相关知识
    函数声明和函数表达式
    js中constructor和prototype
    委托模式
    js跨域
    原型和原型链
    javascript 数据类型
  • 原文地址:https://www.cnblogs.com/lr393993507/p/5286593.html
Copyright © 2011-2022 走看看