【发布时间】:2014-11-20 21:34:26
【问题描述】:
我想同时滚动多个 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 方法滚动。
有人知道我可以如何改进吗?
【问题讨论】:
-
所以,只是为了澄清一下:所有卷轴同时滚动的行为是有意的,它只是关于性能?
-
没错@Markai。
-
它们是否应该实时更新,即当滚动条移动时,或者是否足以在滚动结束时移动它们?
-
Live是理想的,界面的想法是实时比较2行数据/文本
标签: javascript jquery html css