我有这个脚本是我想让它的滚动到15%顶部的偏移量。我尝试了很多东西,所以我很好奇你们会采取什么样的方法。我已经把它简化为什么可行,因为我所有的尝试都失败了。希望有人能帮助我。jquery偏移%而不是px - 可能吗?
$('a[href*=#]').bind('click', function (e) {
e.preventDefault();
var target = $(this).attr("href");
$('html, body').stop().animate({ scrollTop: $(target).offset().top }, 800, function() {
location.hash = target;
});
return false;
});
我在这里做一个小提琴:http://jsfiddle.net/77rFz/
它不是做得很好,看到这个小提琴:http://jsfiddle.net/77rFz/ – implum
如果我删除的位置.hash =目标它停止闪烁,但然后它开始失误,当我打链接2,3等 – implum
真的,我已经更新了jsFiddle(http://jsfiddle.net/77rFz/44/),并会更新上面的答案 – mvieghofer