IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • 技术

锚点 与 scrollIntoView()

Posted 2020-10-10 [幸运]

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了锚点 与 scrollIntoView()相关的知识,希望对你有一定的参考价值。

一、锚点

  <p id="firstAnchor"> 锚点 </p>

  <a href="#firstAnchor"> 跳转 </a>

  js 控制

   1、location.href = "#firstAnchor";      // firstAnchor为锚点名称  

   2、window.location.hash = "#firstAnchor"; // firstAnchor为锚点名称

    经测试:hash只会在跳转到此页面的第一次起作用,再次刷新此页面将不起作用,而href始终起作用

二、scrollIntoView()

 参考:scrollIntoView()
 可以用来实现锚点效果:
  document.getElementById("#firstAnchor").scrollIntoView(true);
 详细介绍API https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
  

三、vue组件 和jQuery插件

  vue :vue-scrollto 待续;

  jQuery: 等待高手补充

 

以上是关于锚点 与 scrollIntoView()的主要内容,如果未能解决你的问题,请参考以下文章

利用a-menu和scrollIntoView()实现菜单式锚点

锚点平滑滚动之scrollIntoView

锚点平滑滚动之scrollIntoView

锚点平滑滚动之scrollIntoView

vue项目中使用锚点

前端好用API之scrollIntoView

(c)2006-2024 SYSTEM All Rights Reserved IT常识