scrollIntoView Scrolls just too far

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

    I solved this problem by using,

    element.scrollIntoView({ behavior: 'smooth', block: 'center' });
    

    This makes the element appear in the center after scrolling, so I don't have to calculate yOffset.

    Hope it helps...

提交回复
热议问题