【发布时间】:2014-04-30 23:29:55
【问题描述】:
我正在尝试使用平滑滚动脚本定位 div 内的锚点。问题是链接没有针对正确的锚点。我有它的工作。想法?
小提琴: http://jsfiddle.net/YtJcL/691/
我基本上是在使用这个脚本:
$(function() {
$('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) +']');
if (target.length) {
$('#wrapper').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
【问题讨论】:
-
更具体的问题可能会得到更具体的答案。