滚动到顶部:
代码如下 | 复制代码 |
$('.scroll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); |
滚动到指定位置:
代码如下 | 复制代码 |
$('.scroll_a').click(function(){$('html,body').animate({scrollTop:$('.a').offset().top}, 800);}); |
示例演示地址效果
源码参考:
代码如下 | 复制代码 |
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>js平滑滚动到顶部、底部、指定地方</title> <script type="text/javascript" src="http://www.111cn.net/Public/js/jquery.min.js"></script> <style> .box{ height:200px; width:100%; background:#ccc; margin:10px 0;} .location{ position:fixed; right:0; bottom:10px; width:20px; background:#FFC; padding:5px; cursor:pointer;color:#003}; </style> </head> <body> <div class="location"> |
原文来自:http://www.daixiaorui.com/read/92.html