
这款网页页面平滑滚动jquery代码,点击链接会让网页平滑滚动到链接对应的位置。
运行效果截图如下:

在线演示地址如下:
http://demo.jb51.net/js/2015/jquery-link-scroll-page-codes/
具体代码如下:
页面平滑滚动jquery代码 script> (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>
希望本文所述对大家jQuery程序设计有所帮助。
