So I'm trying to clone html-content form one div to another, and I've gotten it to work nice, but I want a fade-in/fade-out effect on it (using animate 'opacity', since fadeOut messed up the HTML), however when wrapped in the animation-function my .html():
doesn't work properly.
Here's my code:
JS:
WORKING:
function cloneContent($projectItem) {
$lightbox = jQuery('.lightbox');
$LBChild = $lightBox.find('*'); //any child
$LBChild.each( function(i, e) {
$LBclone = jQuery('.LB-clone'); //item to clone
_LBclasses = this.classList;
for(var i=0,len=_LBclasses.length; i<len; i++) {
if ($LBclone.hasClass(_LBclasses[i])) {
$LBmatch = jQuery(this);
$clonePair = $projectItem.parents('.gallery-item').find('.LB-clone.' + _LBclasses[i]);
$clonePairHtml = $clonePair.html();
$LBmatch.html($clonePairHtml);
}
}
});
} //close cloneContent
NOT WORKING:
function cloneContent($projectItem) {
$lightbox = jQuery('.lightbox');
$LBChild = $lightBox.find('*'); //any child
$LBChild.each( function(i, e) {
$LBclone = jQuery('.LB-clone'); //item to clone
_LBclasses = this.classList;
for(var i=0,len=_LBclasses.length; i<len; i++) {
if ($LBclone.hasClass(_LBclasses[i])) {
$LBmatch = jQuery(this);
$clonePair = $projectItem.parents('.gallery-item').find('.LB-clone.' + _LBclasses[i]);
$clonePairHtml = $clonePair.html();
//When function is wrapped in animation, id doesn't work!
$LBmatch.animate({opacity: 0 },250, function() {
$LBmatch.html($clonePairHtml);
}).animate({opacity : 1}, 500);
}
}
});
} //close cloneContent
Here's a fiddle with some alerts that clarifies the problem: https://jsfiddle.net/popmouth/sg5sq72e/15/