我在页面上有一个div,当我替换内容时,我正在淡入淡出加载gif。当我替换DOM元素时,新的DOM元素不再受jquery的.animate方法的影响,但.css方法仍会影响元素。任何人都知道可能导致这种情况的原因是什么?
代码:
var container = $('#container');
var oldContent = container.find('.Content');
oldContent.find('.LoadingPanel').css('display', '').animate({ opacity: 0.8 });
_ajaxHandler.requestNewData(function(content) {
var newContent = content.find('.Content');
newContent.find('.LoadingPanel').css({
display: '',
opacity: 0.8
});
// Replace in the array and in the DOM
oldContent.replaceWith(newContent);
// This does not work
// newContent.find('.LoadingPanel').animate({ opacity: 0 });
// This does
newContent.find('.LoadingPanel').css({ opacity: 0 });
});
标记:
<div id='container'>
<div class='Content'>
<div class='LoadingPanel'>
<img src='loading.gif' />
</div>
</div>
</div>