js平滑滚动到顶部,底部,指定地方

文章出自:http://www.daixiaorui.com/read/92.html

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

示例演示地址:http://www.daixiaorui.com/Public/demo/js/scroll.html

 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>
时间: 2024-08-03 03:27:25

js平滑滚动到顶部,底部,指定地方的相关文章

jquery实现平滑滚动到顶部、底部、或者指定位置(个人随笔)

个人随笔,欢迎指教. 代码如下: <!doctype html> <html> <head> <meta charset="utf-8"> <title>jquery实现平滑滚动到顶部.底部.或者指定地方</title> <script type="text/javascript" src="JavaScript/jquery-1.11.2.min.js"><

JQuery - 点击,滚动回到顶部 / 底部刷新回到顶部

if ($(document).scrollTop() != 0) { //刷新之后,回到顶部 $('body,html').animate({ scrollTop: 0 }, 500); }

转的滚动事件,慢慢滚到顶部或者指定位置

这篇文章主要介绍了使用jquery animate创建平滑滚动效果,效果可以滚动到顶部.到底部或页面中指定地方,生要的是非常平滑,很舒服,需要的朋友可以参考下 滚动到顶部: $('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); 滚动到指定位置: $('.scroll_a').click(function(){$('html,body').animate({scrollTop:$(

【转】使用jquery animate创建平滑滚动效果

这篇文章主要介绍了使用jquery animate创建平滑滚动效果,效果可以滚动到顶部.到底部或页面中指定地方,生要的是非常平滑,很舒服,需要的朋友可以参考下 滚动到顶部: $('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); 滚动到指定位置: $('.scroll_a').click(function(){$('html,body').animate({scrollTop:$(

js-点击按钮页面滚动到顶部,底部,指定位置

之所以笔记一下这个,因为我在项目中经常用到. $('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); //页面滚动至顶部 $('.scroll_a').click(function(){$('html,body').animate({scrollTop:$('.a').offset().top}, 800);}); //页面滚动至指定的位置 $('.scroll_bottom').

页面中的平滑滚动——smooth-scroll.js的使用

正常的本页面锚链接跳转的时候跟PPT似的,特别生硬,用户体验非常差. 这时候我们就可以借助smooth-scroll.js这个插件,来实现本页面的平滑的跳转. 1首先,导入必须的JS文件 <script src="js/jquery-1.10.2.js"></script> <script src="js/jquery.smooth-scroll.min.js"></script> <script src=&qu

原生js判断某个区域的滚动条滚动到了底部

原生js判断某个区域的滚动条滚动到了底部 讲解==> 关系公式:element.scrollHeight - element.scrollTop === element.clientHeight 解释:此公式可以用于判断是否滚动到底 你必须知道这个方法 可以判断滚动条滚动到了底部哈! element.scrollHeight 是获取这个元素区域的实际高度(包含被隐藏起来的高度) element.scrollTop是获取滚动条距离顶部的实际距离(包含被隐藏起来的高度) element.client

常用JS图片滚动(无缝、平滑、上下左右滚动)代码大全

常用JS图片滚动(无缝.平滑.上下左右滚动)代码大全 今天刚网上看的 不多说直接帖代码---- <head><-----></head><body> <!--向下滚动代码开始--><div id="colee" style="overflow:hidden;height:253px;width:410px;"><div id="colee1"><p>&

图片切换特效(2):JS图片滚动代码(无缝、平滑)

转自:http://www.codefans.net/jscss/code/255.shtml <!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">