![](/img/trans.png)
[英]jQuery animate: scrolltop not working in firefox or web explorer
[英]jQuery animate scrollTop not working in firefox
我的网站上有这个简单的 jQuery 自动滚动代码
$('body[data-pagecontroller="profile"],body[data-pagecontroller="search"]').animate({
scrollTop: $("#ipsLayout_body").offset().top -65
}, 1000);
基本上,如果选择器存在于正文中,则简单的自动滚动到 ipsLayout_body,虽然它在 Microsoft Edge、Chrome、Opera 上运行良好,但在 IE9 和 firefox 上运行良好?
我假设 Firefox 在数据属性和动画方面存在一些问题,但是我总是使用“html, body”来为我想要的元素设置动画,如下所示:
/* IF body[data-pagecontroller="profile"] OR
body[data-pagecontroller="search"] Exists */
if($('body[data-pagecontroller="profile"]').length > 0 || $('body[data-pagecontroller="search"]').length > 0){
$('html,body').animate({scrollTop: $('#ipsLayout_body').offset().top -65 },1000);
}
希望这可以帮助 !
狮子座。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.