Let me preface this by saying I have addressed this thread trying to resolve my issue, but to no avail: Fade in each element - one after another
I thought it would work quite handily if the elements weren't dynamic content, but I made a test div and filled it with thumbnails, and a button to click and assigned similar code, but it still just flat out removed all of the elements without animation or hesitation.
Right now, what I have looks like this:
function OnThumbSuccess(response) {
var $thumbs = $('#Gallery .thumbWindow .thumbReel');
var files = $.parseJSON(response.d);
$thumbs.children().each(function (i) {
$(this).delay(i*300).animate({ 'opacity': '0' }, 500, 'easeOutSine');
$(this).remove();
})
//make sure the thumb reel resets to its original position
$thumbs.css('left', '0px');
//loop through the array of json objects
for (var i = 0; i < files.length; i++) {
//images[i] = files[i].fileHREF;
InsertHTML(files[i].thumbHref, i);
}
}
So, it's supposed to fade that element out, then remove it. It has no problem removing it; it's the animating it that it seems to fail on.
After some tinkering around, I have discovered that I CAN indeed animate them however I please, provided I get rid of $(this).remove()
. That would be fine, if I didn't need to get rid of those elements.
It doesn't seem to matter what I do. I've tried chaining the .remove()
to the end of the animate function, I've tried setting a delay equal to the number of elements before emptying the div. I've tried moving the code to populate the thumbnails div from the OnThumbSuccess function to the ajax.done() function.
I'm really at a loss as to how I can do this elegantly. Please let me know what, if any other details I can provide.
I made this test fiddle, maybe this will be of some help: http://jsfiddle.net/kum8d7k9/