码迷,mamicode.com
首页 > 其他好文 > 详细

页面滚动到指定元素区域

时间:2019-12-13 00:13:22      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   query   foo   可见   doc   code   scroll   into   pre   

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

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

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

 

页面滚动到指定元素区域

标签:style   query   foo   可见   doc   code   scroll   into   pre   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!