JavaScript window.scroll 还是 window.scrollTo?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1925671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 21:55:25  来源:igfitidea点击:

JavaScript window.scroll vs. window.scrollTo?

javascript

提问by Tom

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

知道window.scroll(x, y)window.scrollTo(x, y)[不谈论 jQuery]之间有什么区别吗?

Also any ideas as to which browsers support which? Thanks

还有关于哪些浏览器支持哪些的任何想法?谢谢

采纳答案by Thomas Bonini

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

没有区别:https: //developer.mozilla.org/en/DOM/window.scroll

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

据我所知,所有主流浏览器都支持。

回答by jaguarj

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

Window.scrollTo()实际上与window.scroll(x,y)方法相同。要滚动特定距离,请使用Window.scrollBy()

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

另见Window.scrollByLines(),Window.scrollByPages()Element.scrollIntoView()

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

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

回答by jaguarj

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

scrollTo、scroll 和 scrollBy!显然没有涵盖此功能的标准,因此所有浏览器可能不会以相同的方式实现它。