zoukankan      html  css  js  c++  java
  • js平滑滚动到顶部,底部,指定地方

    原文链接

    采用锚点进行页面中的跳转的确很方便,但是要想增加网页的效果,可以使用jquery中的animate,实现滚动的一个动作,慢慢的滚动到你想跳转到的位置,从而看起来会非常高大上。

    示例演示地址

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     5 <title>js平滑滚动到顶部、底部、指定地方</title>
     6 <script type="text/javascript" src="http://www.daixiaorui.com/Public/js/jquery.min.js"></script>
     7 <style>
     8     .box{ height:200px; width:100%; background:#ccc; margin:10px 0;}
     9     .location{ position:fixed; right:0; bottom:10px; width:20px; background:#FFC; padding:5px; cursor:pointer;color:#003};
    10 </style>
    11 </head>
    12 
    13 <body>
    14 <div class="box"></div>
    15 <div class="box"></div>
    16 <div class="box"></div>
    17 <div class="box"></div>
    18 <div class="box a">产品介绍产品介绍 http://www.daixiaorui.com 产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍产品介绍</div>
    19 <div class="box"></div>
    20 <div class="box"></div>
    21 <div class="box"></div>
    22 <div class="box"></div>
    23 <div class="box bottom"></div>
    24 
    25 <div class="location">
    26   <p class="scroll_top">返回顶部</p>
    27   <p class="scroll_a">产品介绍</p>
    28   <p class="scroll_bottom">滑到底部</p>
    29 </div>
    30 <script type="text/javascript">
    31     jQuery(document).ready(function($){
    32         $('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); 
    33         $('.scroll_a').click(function(){$('html,body').animate({scrollTop:$('.a').offset().top}, 800);});
    34         $('.scroll_bottom').click(function(){$('html,body').animate({scrollTop:$('.bottom').offset().top}, 800);});
    35     });
    36 </script>
    37 </body>
    38 </html>
    有错误的请多多指教,共同进步(๑•ᴗ•๑)
    By听雨的人
  • 相关阅读:
    226. Invert Binary Tree
    404. Sum of Left Leaves
    112. Path Sum (判断路径和是否等于某值)
    5 用两个栈实现队列
    111. Minimum Depth of Binary Tree
    110. Balanced Binary Tree
    4 重建二叉树
    108. Convert Sorted Array to Binary Search Tree
    235. Lowest Common Ancestor of a Binary Search Tree(LCA最低公共祖先)
    3 从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/GoCircle/p/6109351.html
Copyright © 2011-2022 走看看