JavaScript window.scroll vs. window.scrollTo?

前端 未结 3 1364
小鲜肉
小鲜肉 2020-12-05 12:26

Any idea what, if any, difference there is between window.scroll(x, y) and window.scrollTo(x, y) [not talking about jQuery]?

Also any ideas

相关标签:
3条回答
  • 2020-12-05 13:10

    There are no differences: https://developer.mozilla.org/en/DOM/window.scroll

    As far as I know, all major browsers support both.

    0 讨论(0)
  • 2020-12-05 13:10

    Window.scrollTo() is effectively the same as the window.scroll(x,y) method. For scrolling a particular distance, use Window.scrollBy().

    Also see Window.scrollByLines(), Window.scrollByPages() and Element.scrollIntoView()

    MDN - https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll

    0 讨论(0)
  • 2020-12-05 13:10

    There is scrollTo, scroll, and scrollBy! Apparently there is no standard covering this functionality so all Browsers may not implement it the same.

    0 讨论(0)
提交回复
热议问题