所以我想以一個DIV克隆HTML的內容形式到另一個,我已經得到了它的工作不錯,但我想淡入/淡出效果就可以了(使用動畫「不透明」,因爲淡出搞砸HTML),然而,當包裹在動畫功能我.html():
不能正常工作。 這裏是我的代碼:JQuery的:當動畫包裹通過匹配不工作類調用的函數
JS:
工作:
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
不工作:
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
下面是一些提示小提琴來闡明這個問題:https://jsfiddle.net/popmouth/sg5sq72e/15/
嘗試像這樣 - > https://jsfiddle.net/Lvxo9xax/ – adeneo
謝謝,我是有點不清楚什麼是不工作...我會更新我的問題。 –
哦,我明白了。這是[內環路閉合(https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example)一式二份,並記下所有的變量都** **全球 – adeneo