scrollIntoView Scrolls just too far

前端 未结 21 2043
盖世英雄少女心
盖世英雄少女心 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:08

    Found a workaround solution. Say that you want to scroll to an div, Element here for example, and you want to have a spacing of 20px above it. Set the ref to a created div above it:

    Doing so will create this spacing that you want.

    If you have a header, create an empty div as well behind the header and assign to it a height equal to the height of the header and reference it.

提交回复
热议问题