找到你要的答案

Q:Scrolling to element inside scrollable container div not working

Q:滚动滚动容器div元素内不工作

I want to scroll to elements (.list-view-items) inside the following container

<div id='list-view'>
  <ul>
    <li class='list-view-item'>
      ...
    </li>
    ...
  </ul>
</div>

#list-view {
  height: 100%;
  border-right: 1px dotted @gray;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#list-view ul {
  position: relative;
  overflow: scroll;
  list-style-type: none;
  padding: 0px;
}

I have tried manually scrolling in chrome devtools with

$('#list-view ul').scrollTop = 1000

But nothing happens

我想在下面的容器中滚动元素(列表视图项)

<div id='list-view'>
  <ul>
    <li class='list-view-item'>
      ...
    </li>
    ...
  </ul>
</div>

#list-view {
  height: 100%;
  border-right: 1px dotted @gray;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

#list-view ul {
  position: relative;
  overflow: scroll;
  list-style-type: none;
  padding: 0px;
}

我试过手动滚动在Chrome开发工具与

$('#list-view ul').scrollTop = 1000

但是什么都没发生

answer1: 回答1:

when using jQuery, scrollTop is a method, so you need to set the value as a parameter

$('#list-view ul').scrollTop(1000)

使用jQuery的时候,scrollTop是一种方法,所以你需要设置的值作为参数

$(“#列表视图UL)scrollTop(1000)。

answer2: 回答2:

You need to change the CSS, adding a height to both elements, and adding overflow:scroll to the parent element.

See this demo.

你需要改变CSS,添加一个高度元素,并加入溢出:滚动到父元素。

看到这个演示。

javascript  jquery