php文字左右平滑滚动代码,jquery实现网页的页面平滑滚动效果代码

本文实例讲述了jquery实现网页的页面平滑滚动效果代码。分享给大家供大家参考,具体如下:

这款网页页面平滑滚动jquery代码,点击链接会让网页平滑滚动到链接对应的位置。

运行效果截图如下:

7ddf5c04fd78934213e68efd0b9f5cae.png

在线演示地址如下:

具体代码如下:

/p>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

页面平滑滚动jquery代码

(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);

$(function(){

// $("#a111").scrollTo(600,2妯悜)

$("#a111").scrollTo(700)

});

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;}

网页1
网页2
网页3

希望本文所述对大家jQuery程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值