admin管理员组

文章数量:1571369

项目里需要用到屏幕滚到的行为。查询api 之后发现了滚动接口中的两个。然后又很奇怪他们直接的区别,应该如何选择。

首先时mdn的解释,这里说一句,mdn此处的翻译不是特别的准确,也可能是按照功能去翻译的。

 scroll()

The scroll() method of the Element interface scrolls the element to a particular set of coordinates inside a given element.

scrollTo()

The scrollTo() method of the Element interface scrolls to a particular set of coordinates inside a given element.

看起来区别不大,然后看一下规范草案给出的定义

放上链接: https://drafts.csswg/cssom-view/#dom-element-scrollto

核心表述是这句话 Let document be the element’s node document. 这个是浏览器实现的功能。

往下看 还有一句话: When the scrollTo() method is invoked, the user agent must act as if the scroll() method was invoked with the same arguments.

也就是说这俩对于浏览器实现的时候表现要一致。

总结来说,确实没什么区别。至于为什么有两个,我也不清楚。浏览器具体怎么去实现规范,这个就视情况而定了。

本文标签: 区别ScrollscrollTo