scrollIntoView Scrolls just too far

前端 未结 21 2029
盖世英雄少女心
盖世英雄少女心 2020-12-07 10:08

I have a page where a scroll bar containing table rows with divs in them is dynamically generated from the database. Each table row acts like a link, sort of like you\'d see

21条回答
  •  自闭症患者
    2020-12-07 11:02

    Another solution is to use "offsetTop", like this:

    var elementPosition = document.getElementById('id').offsetTop;
    
    window.scrollTo({
      top: elementPosition - 10, //add your necessary value
      behavior: "smooth"  //Smooth transition to roll
    });
    

提交回复
热议问题