jquery实现网页的页面平滑滚动效果代码
作者:bea
本文实例讲述了jquery实现网页的页面平滑滚动效果代码。分享给大家供大家参考,具体如下: 这款网页页面平滑滚动jquery代码,点击链接会让网页平滑滚动到链接对应的位置。 运行效果截图如下: 在线演示地址如下: http://demo./js/2015/jquery-link-scroll-page-codes/ 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http
本文实例讲述了jquery实现网页的页面平滑滚动效果代码。分享给大家供大家参考,具体如下:
这款网页页面平滑滚动jquery代码,点击链接会让网页平滑滚动到链接对应的位置。
运行效果截图如下:
在线演示地址如下:
http://demo./js/2015/jquery-link-scroll-page-codes/
具体代码如下:
<!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>页面平滑滚动jquery代码</title>
<script type="text/javascript" src="jquery1.3.2.js"></script>
<script type="text/javascript">
(function($){
$.extend($.fn,{
scrollTo:function(time,to){
time=time||800;
to=to||1;
$('a[href*=#]', this).click(function(){
if (location.pathname.replace(/^//, '') == this.pathname.replace(/^//, '') &&
location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
if (to == 1) {
$('html,body').animate({
scrollTop: $target.offset().top
}, time);
}
else if(to==2){
$('html,body').animate({
scrollLeft: $target.offset().left
}, time);
}else{
alert('argument error');
}
return false;
}
}
});
}
});
})(jQuery);
</script>
<script type="text/javascript" language="javascript">
$(function(){
// $("#a111").scrollTo(600,2妯悜)
$("#a111").scrollTo(700)
});</script>
<style type="text/css" >
html{ _overflow:hidden}
body {margin:0; height:100%; overflow-y:auto}
#a111 { position:fixed; width:1000px; left:10%;}
* html #a111 {position:absolute;}
#a111 a{ display:block; width:50px; height:20px; background:#000; color:#fff; float:left;}
#a111 a:hover{ background:#f60;}
#b11{ height:1000px; background:#090;}
#b22{ height:1000px; background:#fc0;}
#b33{ height:1000px; background:#09d;}
</style>
</head>
<body>
<div id="a111">
<a href="#b11">mao1</a>
<a href="#b22">mao2</a>
<a href="#b33">mao3</a>
</div>
<div id="b11">网页1</div>
<div id="b22">网页2</div>
<div id="b33">网页3</div>
</body>
</html>
希望本文所述对大家jQuery程序设计有所帮助。
有用 | 无用
这款网页页面平滑滚动jquery代码,点击链接会让网页平滑滚动到链接对应的位置。
运行效果截图如下:
在线演示地址如下:
http://demo./js/2015/jquery-link-scroll-page-codes/
具体代码如下:
<!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>页面平滑滚动jquery代码</title>
<script type="text/javascript" src="jquery1.3.2.js"></script>
<script type="text/javascript">
(function($){
$.extend($.fn,{
scrollTo:function(time,to){
time=time||800;
to=to||1;
$('a[href*=#]', this).click(function(){
if (location.pathname.replace(/^//, '') == this.pathname.replace(/^//, '') &&
location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']');
if ($target.length) {
if (to == 1) {
$('html,body').animate({
scrollTop: $target.offset().top
}, time);
}
else if(to==2){
$('html,body').animate({
scrollLeft: $target.offset().left
}, time);
}else{
alert('argument error');
}
return false;
}
}
});
}
});
})(jQuery);
</script>
<script type="text/javascript" language="javascript">
$(function(){
// $("#a111").scrollTo(600,2妯悜)
$("#a111").scrollTo(700)
});</script>
<style type="text/css" >
html{ _overflow:hidden}
body {margin:0; height:100%; overflow-y:auto}
#a111 { position:fixed; width:1000px; left:10%;}
* html #a111 {position:absolute;}
#a111 a{ display:block; width:50px; height:20px; background:#000; color:#fff; float:left;}
#a111 a:hover{ background:#f60;}
#b11{ height:1000px; background:#090;}
#b22{ height:1000px; background:#fc0;}
#b33{ height:1000px; background:#09d;}
</style>
</head>
<body>
<div id="a111">
<a href="#b11">mao1</a>
<a href="#b22">mao2</a>
<a href="#b33">mao3</a>
</div>
<div id="b11">网页1</div>
<div id="b22">网页2</div>
<div id="b33">网页3</div>
</body>
</html>
希望本文所述对大家jQuery程序设计有所帮助。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- jQuery实用技巧必备(中)
- jQuery实用技巧必备(上)
- jQuery zclip插件实现跨浏览器复制功能
- JQuery zClip插件实现复制页面内容到剪贴板
- jquery实现简洁文件上传表单样式
- Jquery效果大全之制作电脑健康体检得分特效附源码下载
- js实现动态加载脚本的方法实例汇总
- Jquery时间轴特效(三种不同类型)
- Jquery全屏相册插件zoomvisualizer具有调节放大与缩小功能
- 关注jquery技巧提高jquery技能(前端开发必学)
- 18个非常棒的jQuery代码片段
- js实现文件上传表单域美化特效
- 非常实用的12个jquery代码片段
- jQuery+CSS3折叠卡片式下拉列表框实现效果
- jquery 表单验证之通过 class验证表单不为空
- 纯javascript移动优先的幻灯片效果
- JS实现点击按钮获取页面高度的方法
- 基于jQuery实现自动轮播旋转木马特效
- 详解jQuery向动态生成的内容添加事件响应jQuery live()方法