Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Carousel - Issue adding Queue
    primarykey
    data
    text
    <p>I am using a jQuery carousel to display 5 list items at a time, when clicked left or right the code will move the list the appropriate width to display a new item. The problem I have is when the user clicks the left or right button multiple times quickly the function will move in an ugly matter.</p> <p>stop().animate will not work because it stops the animation not the calculation</p> <p>I need to essientially queue the function everytime the user calls it or disable the call mechanism while the function is still running? Any idea on how to accomplish this</p> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function() { $('.brand-carousel-inner li:first').before($('.brand-carousel-inner li:last')); }); function brandSlide(direction) { //Create width variables var brand_item_total_width = 196; //Create movement variable by adjusting the LEFT position +/- if (direction == 'left') { var movement = parseInt($('.brand-carousel-inner').css('left')) + brand_item_total_width; } else { var movement = parseInt($('.brand-carousel-inner').css('left')) - brand_item_total_width; } //Apply movement variable, animate carousel and reposition UL $('.brand-carousel-inner').animate({ 'left': movement }, 700).promise().done(function() { if (direction == 'left') { $('.brand-carousel-inner li:first').before($('.brand-carousel-inner li:last')); } else { $('.brand-carousel-inner li:last').after($('.brand-carousel-inner li:first')); } $('.brand-carousel-inner').css({ 'left': '-196px' }); }); } </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;section id="brand-carousel"&gt; &lt;a href="#" onclick="brandSlide('left'); return false" class="nav-left"&gt;&lt;/a&gt; &lt;a href="#" onclick="brandSlide('right'); return false" class="nav-right"&gt;&lt;/a&gt; &lt;div class="brand-mask"&gt; &lt;ul class="brand-carousel-inner"&gt; &lt;li&gt;&lt;img src="image/image.jpg" /&gt;&lt;/li&gt; /*20 more list items*/ &lt;/ul&gt; &lt;/div&gt; &lt;/section&gt; </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