页面滚动到指定元素区域

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

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

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

猜你喜欢

转载自www.cnblogs.com/zhenguo-chen/p/12032165.html