Jquery 修复 firefox 中的动画错误
Jquery animate bug in firefox
我使用此代码,但好像偏移量从来都不好。
偏移的目标:我的菜单栏保持在顶部。因此,当我单击菜单项时,它会滚动到顶部。减去菜单的高度。但我总是有一个再次滚动的故障。
在 chrome 中工作正常,但在 Firefox 和 IE 中不工作。清楚了吗?
$('html, body').animate({
scrollTop: $(this.hash).offset().top - menu.offsetHeight
}, 300, function(){
window.location.hash = hash;
});
The .animate()
method allows us to create animation effects on any numeric CSS property
所以 scrollTop
不是 CSS 属性,而是 jQuery 函数。如果它是 relative/absolute 定位元素,请将其更改为 margin-top
、padding-top
或 top
。
终于明白了。
不是滚动条。
是:
window.location.hash = hash;
在 IE 和 Chrome 中,当为散列分配一个新值时 属性 滚动到它。
我使用此代码,但好像偏移量从来都不好。 偏移的目标:我的菜单栏保持在顶部。因此,当我单击菜单项时,它会滚动到顶部。减去菜单的高度。但我总是有一个再次滚动的故障。
在 chrome 中工作正常,但在 Firefox 和 IE 中不工作。清楚了吗?
$('html, body').animate({
scrollTop: $(this.hash).offset().top - menu.offsetHeight
}, 300, function(){
window.location.hash = hash;
});
The
.animate()
method allows us to create animation effects on any numeric CSS property
所以 scrollTop
不是 CSS 属性,而是 jQuery 函数。如果它是 relative/absolute 定位元素,请将其更改为 margin-top
、padding-top
或 top
。
终于明白了。
不是滚动条。
是:
window.location.hash = hash;
在 IE 和 Chrome 中,当为散列分配一个新值时 属性 滚动到它。