$('a[href*="#"]:not([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) +']');
console.log( $('[name=' + this.hash.slice(1) +']'));
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
这是个锚点滚动插件,看了下有一点不是很明白,$('[name=' + this.hash.slice(1) +']') 这个是应该怎么理解的?
找锚点指向的元素 比如锚点是
锚点的对象可能是<div id="top"></div>或者<div name="top"></div>