我想为一堆图像创建一个垂直的“无限”滚动容器。
这是我到目前为止提出的:
$("#container").on("scroll", function(e) {
if (e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight) {
$(this).scrollTop(0)
}
})
#container {
position: absolute;
left: 2%;
top: 2%;
width: 10%;
height: 90%;
border: 2px solid black;
overflow-x: hidden;
overflow-y: scroll;
}
.image {
width: 100%;
margin-bottom: 10%;
}
#container {
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
}
#container::-webkit-scrollbar {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<img class="image" src="https://streamdata.io/wp-content/uploads/2018/04/stack-overflow-orange.png">
<img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScZ51RNyVfUEnqQECgs-S-lzgCCA64GCIwtcHmvBwGw6hjgPL29A">
<img class="image" src="https://streamdata.io/wp-content/uploads/2018/04/stack-overflow-orange.png">
<img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScZ51RNyVfUEnqQECgs-S-lzgCCA64GCIwtcHmvBwGw6hjgPL29A">
<img class="image" src="https://streamdata.io/wp-content/uploads/2018/04/stack-overflow-orange.png">
<img class="image" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScZ51RNyVfUEnqQECgs-S-lzgCCA64GCIwtcHmvBwGw6hjgPL29A">
<img class="image" src="https://streamdata.io/wp-content/uploads/2018/04/stack-overflow-orange.png">
</div>
我在一个方向上成功实现了滚动,但是我不知道如何实现滚动顶部。我也遇到了一些问题,因为scrollTop(0)
看起来很生涩,无法每次正常工作。