Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从顶部向下滚动_Javascript - Fatal编程技术网

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行?