Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery, stopping clicking during animations
    primarykey
    data
    text
    <p>:D</p> <p>I am currently having much trouble with a jQuery animation. Basically, a button click will quickly start a short animation and collapse a sidebar, widening the main content box to full width (and back again if wanted). The issue is that with quick consecutive clicks, the layout goes all crazy. I have tried this condition:</p> <pre><code>if (!$(this).is(":animated")) { // Code } </code></pre> <p>But it doesn't work. So I have tried .off(), and it shuts off, but I cannot find out how to turn it back .on(). Can someone help me please? Here is what I have: </p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function(){ var $button = $("a#toggle"); var $content = $("div#index_main-content"); var $sidebar = $("div#sidebar"); // Disable quicky clicky $button.click(function() { $button.off().delay(1000).on(); }); // Hide sidebar $button.toggle(function sidebarToggle() { $sidebar.fadeOut(500, function() { $content.animate({width: '100%'}, 500, function() { $button.attr("title", "Click to show the sidebar!").addClass("hiding").removeClass("showing"); }); }); }, // Show sidebar function sidebarToggle() { $content.animate({width: '69.5%'}, 500, function() { $sidebar.fadeIn(500, function() { $button.attr("title", "Click to hide the sidebar!").addClass("showing").removeClass("hiding"); }); }); }); }); &lt;/script&gt; &lt;div id="index_content"&gt; &lt;a title="Click to hide the sidebar" class="showing" id="toggle"&gt;&lt;/a&gt; &lt;div id="sidebar"&gt; &lt;!-- Sidebar: float-right/width-28.5% --&gt; &lt;/div&gt; &lt;div id="index_main-content"&gt; &lt;!-- Content: float-left/width-69.5% --&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Also, there is a live demo <a href="http://www.littlebigplanetfanatic.com/community/" rel="nofollow">here</a>. Like I said before, for some reason, the .on() does not happen. :(</p> <p>Thank you. :)</p>
    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