页面滚动到指定元素区域

Posted zhenguo-chen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了页面滚动到指定元素区域相关的知识,希望对你有一定的参考价值。

该代码段可将指定元素平滑滚动到浏览器窗口的可见区域。

const smoothScroll = element =>
  document.querySelector(element).scrollIntoView({
    behavior: ‘smooth‘
  });

smoothScroll(‘#fooBar‘); 
smoothScroll(‘.fooBar‘); 

 

以上是关于页面滚动到指定元素区域的主要内容,如果未能解决你的问题,请参考以下文章