Note that there are some explanatory texts on larger screens.

plurals
  1. POReset scrollTo() data
    primarykey
    data
    text
    <p>I have some weird problem. I'm using <code>scrollTo()</code> plugin for scrolling my page. I have up and down arrows for vertical scroll and left and right for horizontal scroll. Problem is, when I click on right arrow, it scrolls to right side, then if I click on down arrow, it first goes to left section, then goes down and then it goes right again. But it should scroll only down. As you can see in my code, I reinitalize <code>call()</code> function, so I believe <code>scrollTo()</code> remembers previous position and then follows that previous path.</p> <p>So my question is, how to reset <code>scrollTo()</code> data when I call that function again.</p> <p><strong>Html</strong></p> <pre><code>&lt;section class="main"&gt; &lt;section class="section0"&gt; &lt;img src="1-1.jpg"&gt; &lt;/section&gt; &lt;section class="section0"&gt; &lt;img src="1-2.jpg"&gt; &lt;/section&gt; &lt;section class="section0"&gt; &lt;img src="1-3.jpg"&gt; &lt;/section&gt; &lt;/section&gt; &lt;section class="main"&gt; &lt;section class="section1"&gt; &lt;img src="2-1.jpg"&gt; &lt;/section&gt; &lt;section class="section1"&gt; &lt;img src="2-2.jpg"&gt; &lt;/section&gt; &lt;section class="section1"&gt; &lt;img src="2-3.jpg"&gt; &lt;/section&gt; &lt;/section&gt; </code></pre> <p><strong>Jquery</strong></p> <pre><code>$(document).ready(function(){ call(0); }); function scrollToPosition(element) { if (element !== undefined) { $("html").scrollTo(element, 800, { margin: true }); } } var counter = 0; var call = function(counter) { var sections = $('.section'+counter); var position = 0; var next = $('#up'); var prev = $('#down').hide(); next.click(function(evt) { prev.show(); scrollToPosition(sections[position += 1]); if (position === sections.length - 1) { next.hide(); } }); prev.click(function(evt) { next.show(); scrollToPosition(sections[position -= 1]); if (position === 0) { prev.hide(); } }); } $(function() { var sections = $('.main'); var position = 0; var next = $('#right'); var prev = $('#left').hide(); next.click(function(evt) { counter++; call(counter); prev.show(); scrollToPosition(sections[position += 1]); if (position === sections.length - 1) { next.hide(); } }); prev.click(function(evt) { counter--; call(counter); next.show(); scrollToPosition(sections[position -= 1]); if (position === 0) { prev.hide(); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload