Javascript 从顶部向下滚动
关于Javascript 从顶部向下滚动,javascript,Javascript,关于document.querySelector(this.getAttribute(“href”).scrollIntoView 我想写一个片段sroll到top减去10rem 我找到了一个scroll to top的代码片段,效果很好。但是我的项目中有一个固定的标题。scrollIntoView无法向下移动侧面。我怎样才能在头球下方得到我的第10条边线。我不想使用jquery <script> document.querySelectorAll('a[href^="#
document.querySelector(this.getAttribute(“href”).scrollIntoView
我想写一个片段sroll到top减去10rem
我找到了一个scroll to top的代码片段,效果很好。但是我的项目中有一个固定的标题。scrollIntoView无法向下移动侧面。我怎样才能在头球下方得到我的第10条边线。我不想使用jquery
<script>
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener("click", function(e) {
e.preventDefault();
document.querySelector(this.getAttribute("href")).scrollIntoView({
behavior: 'smooth'
});
});
});
</script>
document.querySelectorAll('a[href^=“#“]”)forEach(anchor=>{
anchor.addEventListener(“单击”,函数(e){
e、 预防默认值();
document.querySelector(this.getAttribute(“href”)).scrollIntoView({
行为:“平滑”
});
});
});
您需要获取document.querySelector(this.getAttribute(“href”))的滚动顶部位置,并将您的10rem添加到该位置,然后再滚动到该位置……您是否可以帮助我完成一些javascript行?