jQuery动画scrollTop在firefox中不起作用

时间:2021-12-03 20:38:20

I have this simple jQuery autoscroll code on my website

我的网站上有这个简单的jQuery自动滚动代码

    $('body[data-pagecontroller="profile"],body[data-pagecontroller="search"]').animate({
    scrollTop: $("#ipsLayout_body").offset().top -65
}, 1000); 

Basically, a simple Auto scroll to ipsLayout_body if the selectors exists within the body, While it works fine on Microsoft Edge, Chrome, Opera but not on IE9 and firefox?

基本上,一个简单的自动滚动到ipsLayout_body如果选择器存在于身体内部,而它在Microsoft Edge, Chrome, Opera但不是IE9和firefox上运行良好。

1 个解决方案

#1


1  

I'm assuming Firefox has some issues with data- attributes and the animation, however I always use "html, body" to animate to the element I want, like this:

我假设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);
}

Hope this helps !

希望这可以帮助!

Leo.

狮子座。

#1


1  

I'm assuming Firefox has some issues with data- attributes and the animation, however I always use "html, body" to animate to the element I want, like this:

我假设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);
}

Hope this helps !

希望这可以帮助!

Leo.

狮子座。