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

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

smoothScroll('#fooBar'); 
smoothScroll('.fooBar'); 

 

相关文章:

  • 2022-01-01
  • 2021-06-21
  • 2021-05-25
  • 2022-12-23
  • 2021-07-21
  • 2022-02-01
  • 2022-12-23
  • 2021-11-26
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案