我希望同时滚动多个div。
目前有一种方法可以实现,但是在性能较差的设备上(尤其是移动设备)表现不佳。
<!-- HTML -->
<div class="container">
<div class="row">
<div class="scroller">
<div>some really long content that just keeps going on and on and on and on and on and on and on and on and on and on and on and on and on</div>
</div>
</div>
<div class="row">
<div class="scroller">
<div>some really long content that just keeps going on and on and on and on and on and on and on and on and on and on and on and on and on</div>
</div>
</div>
<div class="row">
<div class="scroller">
<div>some really long content that just keeps going on and on and on and on and on and on and on and on and on and on and on and on and on</div>
</div>
</div>
<div class="row">
<div class="scroller">
<div>some really long content that just keeps going on and on and on and on and on and on and on and on and on and on and on and on and on</div>
</div>
</div>
<div class="row">
<div class="scroller">
<div>some really long content that just keeps going on and on and on and on and on and on and on and on and on and on and on and on and on</div>
</div>
</div>
</div>
<style>
/* CSS */
.container { width:300px; }
.scroller { width:100%; height:40px; padding:0 0 16px; line-height:40px; overflow-x:auto; overflow-y:hidden; white-space:nowrap; }
</style>
<script>
// jQuery
$(".scroller").scroll(function(){
$(".scroller").scrollLeft($(this).scrollLeft());
});
</script>
我发现当我滚动一个元素时,它会滚动相同类别的其他元素,但由于我在该类别上设置了一个滚动“监听器”,因此对于每个已使用scrollLeft方法滚动的其他元素,函数会再次触发。
有人有任何想法如何改进这个问题吗?