Difference between scroll and scrollTop in javascript / jQuery

What's the difference between:

window.scroll(0,200);

and

$(window).scrollTop(200);

Besides the fact that one of them uses jQuery and the other does not, what is the difference? Does the scroll animate while the other doesn't? Will it work faster than the other?

+4
source share
3 answers

scrollTopuses window.scrollTo, it seems: http://james.padolsey.com/jquery/#v=1.10.2&fn=jQuery.fn.scrollTop

Performance is wiser than a pure js solution faster, obviously, but in most cases it doesn't really matter: http://jsperf.com/js-vs-jquery-scroll

There seems to be no difference in performance between window.scrolland window.scrollTo.

+1
source

.scrollTo() .scroll() window, .scrollTop() DOM

+1

JQuery scrollTop () method - returns the vertical position of the scroll bar for an HTML element JavaScript window.scroll (x-coord, y-coord) scrolls the window to a specific place in the document. Window.scrollTo actually matches this method.

-1
source

Source: https://habr.com/ru/post/1547066/


All Articles