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.
也就是说这俩对于浏览器实现的时候表现要一致。
总结来说,确实没什么区别。至于为什么有两个,我也不清楚。浏览器具体怎么去实现规范,这个就视情况而定了。
版权声明:本文标题:scroll 和 scrollTo 的区别 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1727690252a1125780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论