這是由於IE6中的所有內容都在相同的線程中執行 - 甚至是爲gif製作動畫。
確保在啓動之前顯示gif的唯一方法是通過分離執行。
function longRunningProcess(){
....
hideGif();
}
displayGif();
window.setTimeout(longRunningProcess, 0);
但是,當longRunningProcess
執行時,這仍然會導致瀏覽器凍結。
爲了讓互動,你將不得不打破你的代碼,以更小的片段,也許這樣
var process = {
steps: [
function(){
// step 1
// display gif
},
function(){
// step 2
},
function(){
// step 3
},
function(){
// step 4
// hide gif
}
],
index: 0,
nextStep: function(){
this.steps[this.index++]();
if (this.index != this.steps.length) {
var me = this;
window.setTimeout(function(){
me.nextStep();
}, 0);
}
}
};
process.nextStep();
你有沒有嘗試把JavaScript放入window.onload事件? – NibblyPig 2010-06-08 08:40:13
@SLC它不屬於那裏 – Midhat 2010-06-08 08:58:41