html页面实现 点击页面元素定位

1.滚动到顶部:

a标签实现:<a href="#top">顶部</a>

js实现:location.href = "#top";

2.定位到指定dom元素:

$("#gun")[0].scrollIntoView();或者document.querySelector('#gun').scrollIntoView();

3.指定时间滚动到ID为gun的元素: 

$("html,body").animate({scrollTop: $("#gun").offset().top}, 500);

猜你喜欢

转载自blog.csdn.net/qq_40095973/article/details/81478122