scrollIntoView 函数简化置顶功能

本贴最后更新于 213 天前,其中的信息可能已经时移俗易

基本介绍

Element.scrollIntoView() - Web API 接口参考 | MDN 这是一个实验性的 API,请尽量不要在生产环境中使用它。 This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This is an obsolete API and is no longer guaranteed to work. 这是一个实验性的 API,请尽量不要在生产环境中使用它。 This API has not been standardized. This deprecated API should no longer be used, but will probably still work. 这是一个实验性的 API,请尽量不要在生产环境中使用它。 This API has not been standardized. 这是一个实验性的 API,请尽量不要在生产环境中使用它。 This API has not been standardized. This API has not been standardized. This API has not been standardized. This deprecated API should no longer be used, but will probably still work. This API has not been standardized. This deprecated API should no longer be used, but will probably still work. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This deprecated API should no longer be used, but will probably still work. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized. This deprecated API should no longer be used, but will probably still work. This API has not been standardized. This API has not been standardized. This API has not been standardized. This API has not been standardized.

Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗口的可视区域内。

仔细想想,发现这个功能有很好的的实用性,比如置顶huaji

document.body.scrollIntoView({behavior: 'smooth'})

打开控制台,输入下面代码试试doge

  • JavaScript

    JavaScript 一种动态类型、弱类型、基于原型的直译式脚本语言,内置支持类型。它的解释器被称为 JavaScript 引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在 HTML 网页上使用,用来给 HTML 网页增加动态功能。

    678 引用 • 1137 回帖 • 685 关注

广告 我要投放

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...