DIV auto scroll

后端 未结 5 1030
情话喂你
情话喂你 2021-02-06 10:34

I have a div that has a large number of items in it. I select these items dynamically by clicking a button, overflow is auto in my case. What I want is that when an item that is

5条回答
  •  生来不讨喜
    2021-02-06 11:23

    Yet another option... anchors.

    Assign each item a unique ID, and when you want to scroll to a particular item, execute the following JavaScript code:

    location.hash = itemID;
    

    ...where itemID is a variable that contains the ID of the element you want to scroll to.

    Steve

提交回复
热议问题