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

2019-02-12 02:44发布

This question already has an answer here:

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.

3条回答
Anthone
2楼-- · 2019-02-12 03:45
$(body).scrollTop($(this)[0].scrollHeight);

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

查看更多
三岁会撩人
3楼-- · 2019-02-12 03:46

try using

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

instead of

$("body").animate({scrollTop:$(this).offset().top},800);
查看更多
祖国的老花朵
4楼-- · 2019-02-12 03:47

try this.

document.getElementsByTagName('body')[0].clientHeight
查看更多
登录 后发表回答