Note that there are some explanatory texts on larger screens.

plurals
  1. POchrome is not smooth when for animating a div's left property using jquery animate() method
    primarykey
    data
    text
    <p>I am trying to create a simple image slider but I am having some trouble doing it here is my code so far :</p> <pre><code>&lt;div id="frame"&gt; &lt;div id="slider"&gt; &lt;div id="imageHolder"&gt; &lt;img src="PNGs/Desert.jpg" alt="image" /&gt; &lt;img src="PNGs/Lighthouse.jpg" alt="image" /&gt; &lt;img src="PNGs/Penguins.jpg" alt="image" /&gt; &lt;img src="PNGs/Hydrangeas.jpg" alt="image" /&gt; &lt;img src="PNGs/Koala.jpg" alt="image" /&gt; &lt;/div&gt; &lt;div id="counter"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="button1" style="z-index:100; position:absolute; right:-25px; top:175px; width:50px; height:35px; border-radius:200px; background-color:black; color:white; font-weight:bold; text-align:center; vertical-align:central; padding-top:15px;"&gt;right&lt;/div&gt; &lt;div id="button2" style="z-index:100; position:absolute; left:-25px; top:175px; width:50px; height:35px; border-radius:200px; background-color:black; color:white; font-weight:bold; text-align:center; vertical-align:central; padding-top:15px;"&gt;left&lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>css:</strong></p> <pre><code>#frame { margin:10px auto 0; position:relative; width:1000px; height:400px; } #slider { position:relative; width:1000px; height:400px; background-color:red; overflow:hidden; } #imageHolder { width: 0; height:400px; position:relative; } #imageHolder img { float:left; width:1000px; height:400px; } #counter { display:inline-block; z-index:100; position:absolute; left:10px; bottom: 0; } </code></pre> <p><strong>jQuery:</strong></p> <pre><code>$(window).load(function () { var count = $('#imageHolder img').length; var itemIndex = 1; function MoveSlider(container, count, isForwards) { var containerName = '#' + container.toString(); if (isForwards) { itemIndex++; if (itemIndex &lt; count + 1) $(containerName).animate({ left: ((itemIndex - 1) * -100).toString() + "%" }, 2000, 'easeOutBounce'); else { $(containerName).animate({ left: '0'}, 2000, 'easeOutBounce'); itemIndex = 1; } } else { itemIndex--; if (itemIndex &gt; 0) $(containerName).animate({ left: ((itemIndex - 1) * -100).toString() + "%" }, 2000, 'easeOutBounce'); else { $(containerName).animate({ left: (-(count - 1) * 100).toString() + '%'}, 2000, 'easeOutBounce'); itemIndex = count; } } } var counterHtml = ""; for (var i = 0; i &lt; count; i++) { counterHtml += "&lt;div class=\"index\" style=\"text-align:center; vertical-align:central; color:white; display:inline-block; background-color:black;width:20px; height:20px; border-radius:200px;\"&gt;" + (i + 1) + "&lt;/div&gt;"; } $('#counter').html(counterHtml); $('#imageHolder').css('width', (count * 1000).toString() + 'px'); var timer = setInterval(function () { MoveSlider('imageHolder', count, true); }, 5000); $('#frame').mouseover(function () { clearInterval(timer); }); $('#frame').mouseleave(function () { timer = setInterval(function () { MoveSlider('imageHolder', count, true); }, 5000); }); $('.index').click(function () { itemIndex = $('.index').index(this) + 1; $('#imageHolder').animate({ left: ((itemIndex - 1) * -100).toString() + '%' }, 2000, 'easeOutBounce'); }); $('#button1').click(function () { MoveSlider('imageHolder', count, true); }); $('#button2').click(function () { MoveSlider('imageHolder', count, false); }); }); </code></pre> <p>the animations run smoothly on firefox and IE10, but there is a significant lag for the first 2 or 3 images,and I have no idea what to do with it Any suggestions about my problem? (ps:any suggestion on my javascript code is also appreciated if you think I can make it better...) Thanks in advance</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.
    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