jQuery代码实现Web页内锚点scoll效果
方法原作者:http://www.learningjquery.com
//页内锚点滑动效果,来自http://www.learningjquery.com/的方法
$('a[href*=#]').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) {
var targetOffset = $target.offset().top;
$('html,body')
.animate({scrollTop: targetOffset}, 1000);
//return false; //使其呈现清晰的URL链接
}
}
});
发现网上这段代码被各个站粘贴,以致我也不太清楚原作是谁了,我还是比较相信国外的那些大牛,不过这段代码确实值得转帖分享,在本小站再次分享。
JQuery返回顶部 代码 (wordpress)
开始折腾JQuery!——2010.5.1
以前在网页中使用JavaScript的时候,总感觉这种脚本代码,除了页面提示,貌似就没啥功能了,用了反而会让页面显得很乱。
去年知道JQuery,很好很强大的一个小型的JS库,不过一直没怎么研究过,为了能让自己的博客多一些JS效果,今天开始折腾JQuery。
