锚点滚动效果

1. a 链接直接跳转(无滚动)
<a class="skip-hdgz" href="#hdgz" ></a>
<div id="hdgz"></div>

2.js 滚动锚点效果
function skip() {
   $(".skip-hdgz").click(function() {
     let anchorElement = document.getElementById('hdgz');
     if (anchorElement) {
       anchorElement.scrollIntoView({ behavior: 'smooth' });
     }
   });
}
skip();
scrollIntoView:发现兼容问题 安卓会有滚动,IOS没有

 

原文地址:https://www.cnblogs.com/jiaqi1719/p/13066137.html