【发布时间】:2015-08-02 03:46:55
【问题描述】:
我在平滑滚动到具有固定导航的视差 div 中的锚点时遇到了一些问题。
该脚本从页面顶部运行良好,但一旦进入内容,链接就会驱动到错误的锚点......
我尝试了几个脚本,但遇到了同样的问题(从顶部工作正常,但从内容失败)。
$(document).ready(function() {
$(".scroll").click(function (e) {
e.preventDefault();
if (this.hash) {
//get rid of hash
var hash = this.hash.substr(1);
//get the position of the <a name>
var $toElement = $("[id=" + hash + "]");
var toPosition = $toElement.offset().top;
//scroll/animate that element
$(".parallax").animate({
scrollTop: toPosition
}, 500);
}
});
});
这里是代码:http://jsfiddle.net/63hy5urr/1/
请帮忙。
谢谢。
【问题讨论】:
标签: jquery scroll anchor parallax smooth