简体   繁体   English

如何使用iScroll同时滚动2个div

[英]how to scroll 2 divs at the same time with iScroll

I have 2 divs that both uses iScroll. 我有两个都使用iScroll的div。 Now I would like both divs to scroll when one of them are scrolled. 现在,当两个div滚动时,我希望两个div滚动。

I want them to scroll simultaneously 我希望他们同时滚动

Is this possible? 这可能吗?

Try structuring the div as follows : 尝试如下构造div

<div id=wrapper>
 <div id="scroller">
   <div id="div1">
     <div id="child1"></div>
   </div>
   <div id="div2">
     <div id="child2"></div>
   </div>
 </div>
</div>

Then define iscroll for #wrapper and you get to scroll both the div simultaneously. 然后为#wrapper定义iscroll,您将同时滚动两个div。 This is the easy way. 这是简单的方法。

Or you can try to get the onScroll event . 或者,您可以尝试获取onScroll event Though it is not possible to exactly get on scroll position during scroll but you can still get is in on onScrollMove and onScrollEnd . 尽管不可能在滚动过程中精确到达滚动位置,但是仍然可以在onScrollMoveonScrollEndonScrollMove onScrollEnd Hope this helps you. 希望这对您有所帮助。

You can use scrollTo method to scroll the second div at a specified position on scrolling any div. 滚动任何div时,可以使用scrollTo方法在指定位置滚动第二个div。 It takes three arugments out of which timeout is optional. 它需要三个时间间隔,其中超时是可选的。

scrollTo(x, y, timeout) - scrolls to any x,y location inside the scrolling area. scrollTo(x, y, timeout) -滚动到滚动区域内的任何x,y位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM