<a href="#one">one</a>
<a href="#two">two</a>
<a href="#three">three</a>
<div id="one">oneone</div>
<div id="two">two</div>
<div id="three">three</div>
div{
width:100%;
height:500px;
background:#ff6600;
margin-bottom:10px;
}
<script>
$(function() {
// 锚点链接
//a标签使用name,其它标签使用id
$('a').click(function(){
//根据a标签的href转换为id或a标签的name,获取id元素或a标签所处的位置,平滑的滚动的
let $id = $(this).attr('href');
let $offset = $($id).offset().top;
//let $offset = $(`[name=${$id}]`).offset().top;
$('html,body').animate({
scrollTop: ( $offset )
},1000);
});
})
</script>