带锚点URL同一页面滚动效果的实现
得出几点结论
1,[] 在jquery选择器里
表示属性-选择
2,:not() 后置定语
3,()表示 函数参数
4,location 有好多个属性
5, animate({对象在这里}) -- 对象
------------------------------------------
jQuery(function() {
jQuery('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
if (target.length) {
jQuery('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
浙公网安备 33010602011771号