Scrolling inner div on key down and up

前端 未结 5 1872
你的背包
你的背包 2021-02-05 20:37

I have build an autocomplete container which displays the first four results and the rest are hidden and can be seen when scrolling the inner div element which holds all the res

5条回答
  •  孤独总比滥情好
    2021-02-05 20:47

    Two years passed... just in case someone stumbles over this, like me. In addition to the last two lines in Moobs answer (can't do any comments yet...), plain Javascript:

    (Left out: how to get elements in pure JS), then:

    $innerDiv.scrollTop = $hoveredElement.offsetTop - $innerDiv.clientHeight;

    There also seems to be no need to "reset" scrollTop to zero before assigning the new value

提交回复
热议问题