Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After reviewing your code I would say the primary reason for lag in animation is that your slices are being added as individual dom elements and the animation is having to not only push those around but operate off non specific selectors...</p> <p>Correct me if I'm wrong but it looks like you're basically pushing the latest to the top and moving it in view over a 1 second span of time. If this is the case at any point you would only have 2 frames in view at a time, right?</p> <p>I would create a javascript object and use that to populate 2 specific dom elements for manipulation.</p> <pre><code>&lt;div id="current"&gt;&lt;/div&gt; &lt;div id="next"&gt;&lt;/div&gt; </code></pre> <p>then manipulate the css of these elements through the animation callback and applicable index of your js object. This example may not reflect your needs but the principal is the same:</p> <pre><code>var slices = { current: 0, image_arr: new Array(), animating: false, queue: null, delay: 150, init: function(){ // obviously declare these variables and access them relevantly for(imageN=0;imageN&lt;imageCount;imageN++) { this.image_arr.push($("#image img:eq("+imageN+")").attr("src")); } }, animate: function(){ if(!animating) { this.animating = true; // cycle through your image_arr instead of crawling the dom each iteration // set jquery animations as expected then re-call function if needed $('#current').css('background-image', this.image_arr[current]).delay(50).animate({marginTop: '700px'}, 1000, function(){ this.current += 1; // assuming you're using an int to call the index value of image_arr }); $('#next').css({backgroundImage: this.image_arr[current], marginTop: '-700px').delay(50).animate({marginTop: '0px'}, 1000); this.queue = setTimeout(function(){ this.animate(); }, this.delay); //this should obviously be more considerate, but the idea is to recursively call animate until you're through animating } } }; $(document).ready(function(){ slices.init(); }); </code></pre> <p>This example is not at all stable or tested and clearly will not work if you copy / paste, but the general idea is to push your slice elements into an array or object. you can of course push an object for each slice into the array as well. Whatever suits your needs.</p> <p>But this way you don't have to traverse the entire dom on every frame.</p> <p>I can answer more specifically if you were to say - post a link to your actual animation. Since I don't see it in action I just guessed what I was looking at and I may have got it totally wrong.</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. VO
      singulars
      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