how to scroll 2 divs at the same time with iScroll

843 views Asked by At

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?

2

There are 2 answers

0
ShankarSangoli On

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.

0
user850234 On

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.