scrollTop doesn't work on firefox and IE? [dup

2019-02-12 03:05发布

问题:

This question already has an answer here:

  • Animate scrollTop not working in firefox 11 answers

I have below code which works fine in chrome.

However, it does not work on firefox and also IE. Nothing happens.

 $("body").animate({scrollTop:$(this).offset().top},800);

So may i ask what i should write for firefox and IE??

Thanks.

回答1:

try using

$('body,html').animate({scrollTop:$(this).offset().top},800);

instead of

$("body").animate({scrollTop:$(this).offset().top},800);


回答2:

try this.

document.getElementsByTagName('body')[0].clientHeight


回答3:

$(body).scrollTop($(this)[0].scrollHeight);

you use this code ,i think it will work properly in IE and Firefox