页面滚动到指定元素区域

时间:2019-12-12 23:35:05   收藏:0   阅读:117

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

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

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

 

原文:https://www.cnblogs.com/zhenguo-chen/p/12032165.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!