0

I know a similar question has been asked and answered here - jQuery .scrollTop(); + animation.

I was trying to understand why if I try this-

 $(window).animate({scrollTop:300},500) 

The page does not scroll.

However, if I try the below one as suggested in an earlier SO question, it works fine -

 $('html,body').animate({scrollTop:300},500).

What's more confusing is, if I just try the following (without any animation), it works fine -

$(window).scrollTop(300);

Can someone please help to understand what I am getting wrong here?

Community
  • 1
  • 1
Shibasis Sengupta
  • 629
  • 1
  • 6
  • 21

1 Answers1

0

Because the scrollTop property works with(scrolls) the elements inside the window(html, body etc.) and not the window itself.

Sudipto
  • 440
  • 2
  • 8