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,797
  • 6
  • 31
  • 43
kfirba
  • 5,231
  • 14
  • 41
  • 70

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,603
  • 9
  • 39
  • 61
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