What is the logic for this action?
<p>I have an array which is page:['null',0,1000,2000]
I have a variable scrollx, which detect user scrolling x position
I have a function scrollto(), input a number will scroll to that position with animation</p>

<p>What I want to do is when scrollx is smaller than half of page[3] which is 1500, it will scrollto(page[2]), like scrollx 1200,1300,1400, it will goes to page[2], otherwise it goes page[3].</p>

<p>but I cant think of a good solution...</p>

<pre><code>$viewport.on('touchend',function(event){
    for(i=1;i&lt;=total;i++){
     if(scrollx &lt; page[i]/2 || scrollx &gt; page[i]/2){
      scrollto(page[i]);
    }
})
</code></pre>

<p>I messed up, thats seems not logical...which page it goes to... now I have the current page positions,all the other pages positions but..what should I do?</p>
