1

I've got the following code in order to ease a scroll to the top of a page:

 $(document).ready(function(){
    $('#top').on("click",function(){
        $("body").stop().animate({scrollTop: 0},"slow");
    });
})

It works perfectly fine on chrome, doesn't work on IE, in IE, the scrollbar doesn't even move. Nothing happens.

Any suggestions how to deal with it?

nietonfir
  • 4,697
  • 6
  • 29
  • 43
kfirba
  • 4,773
  • 13
  • 38
  • 68

2 Answers2

3

For IE, you may need to add html to your selector for the animation, as IE does not seem to recognize the animation on the body element.

Try this:

 $(document).ready(function(){
    $('#top').on("click",function(){
        $("html, body").stop().animate({scrollTop: 0},"slow");
    });
})
Rich
  • 5,417
  • 9
  • 36
  • 58
3

Have you tried Googling?

$('body, html').animate({scrollTop : 0}, 0);

jQuery animate scrollTop not working in IE 7

Community
  • 1
  • 1
  • Well, I didn't really know what to google. BTW, I didn't think it was something to do with the selector since it did work a week ago, and now it doesn't. But hey, thanks for the answer! – kfirba Oct 12 '13 at 21:59
  • Yeah no problem! I'm glad that it works :) –  Oct 12 '13 at 22:00