how to scroll 2 divs at the same time with iScroll

蹲街弑〆低调 提交于 2021-02-08 06:33:38

问题


I have 2 divs that both uses iScroll. Now I would like both divs to scroll when one of them are scrolled.

I want them to scroll simultaneously

Is this possible?


回答1:


You can use scrollTo method to scroll the second div at a specified position on scrolling any 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.




回答2:


Try structuring the div as follows :

<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. This is the easy way.

Or you can try to get the 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. Hope this helps you.



来源:https://stackoverflow.com/questions/8806811/how-to-scroll-2-divs-at-the-same-time-with-iscroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!