大家好,我有一个非常简单的功能
enableModule : function(moduleName){
var module = $('div#'+moduleName);
console.log('enabling '+moduleName);
console.time('animate');
module.animate({'opacity' : '1.0'}, 300, function(){console.timeEnd('animate');});
module.find('.disabled_sheild').remove();
module.removeClass('disabled');
console.log('end of enable Module');
}
动画本身,不透明度变化,非常快,但调用它时会有延迟。console.time() 报告的时间为 2540 毫秒或更大。我在想这可能是因为 div#module 正在与它的孩子一起被动画化?但这很有意义,因为我有另一个函数“disableModule”,它反向执行相同的操作并以合理的速度运行。
这是禁用模块功能,要进行的操作要多得多,但返回时间约为 242 毫秒
disableModule : function(moduleName){
$('div#'+moduleName+', div.'+moduleName).each(function(){
var module = $(this);
module.prepend('<div class="disabled_sheild"></div>');
var sheild = module.find('.disabled_sheild');
sheild.css({'position' : 'absolute', 'z-index' : '200'});
sheild.width(module.width());
sheild.height(module.height());
jQuery.each(jQuery.browser, function(i) {
if($.browser.msie){
//module.css("display","none");
//if using ie give sheild a transparent background layout
}else{
console.time('animate');
module.animate({'opacity' : '0.5'}, function(){ console.timeEnd('animate');});
}
});
});
}