Note that there are some explanatory texts on larger screens.

plurals
  1. POrepeating a jquery click activated animation function
    primarykey
    data
    text
    <p>I have scoured the internet for over a day and had no hope so I present you with my issue:</p> <p>I have tried using .toggle() and if/else statements but struggled to implement the window_width, element_width and edge dimensions that are implemented into the below JS. </p> <p>In the code below - </p> <p>I have a blue and green span that individually animate the red parent span to the edges of the browser window, the green goes to the far right and the blue to the far left. Now this works fine until I try and repeat the process. So say I go left and then right...I can no longer go left, and vice versa. My question is how can I make this animation work indefinitely so I can constantly switch between the left and right hand sides of the browser window?</p> <p>Like to thank everyone in advance for helping me out. Greatest appreciation. Cheers </p> <p>JS-</p> <pre><code>$(document).ready(function(){ $('#two').click(function(){ window_width = $(document).width(); element_width = $('#one').width(); edge = window_width - element_width; $('#one').animate({right:edge}, 2000).delay(1000); }); }); $(document).ready(function(){ $('#three').click(function(){ window_width = $(document).width(); element_width = $('#one').width(); edge = window_width - element_width; $('#one').animate({left:edge}, 2000).delay(1000); }); }); </code></pre> <p>HTML-</p> <pre><code>&lt;span id='one'&gt;&amp;nbsp; &lt;span id='two'&gt;&amp;nbsp;&lt;/span&gt; &lt;span id='three'&gt;&amp;nbsp;&lt;/span&gt; &lt;/span&gt; </code></pre> <p>CSS-</p> <pre><code>#one { height:100px; width:210px; background-color:red; position:absolute; right:0; } #two { height:100px; width:100px; background-color:blue; float:left; } #three { height:100px; width:100px; background-color:green; float:right; } </code></pre> <p>If at all interested about it's purpose and how it will be implemented into a site - the blue (#two) and green (#three) spans will be used as buttons for two halves of a website, when selected which half you wish to view the buttons move aside to reveal the appropriate content for that half. Once to the side if the viewer selects the other button then the current content disappears whilst the buttons move to the other side of the browser, once stationed to the other side the new (other half) content appears. </p>
    singulars
    1. This table or related slice is empty.
    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.
    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