2013-11-27 45 views
2

我已經開發了下面的代碼,每x秒只交換一個圖像。所有工作正常,並返回在Chrome中沒有錯誤。但是,在IE(最新回到IE8)中,它什麼都不做,不返回任何錯誤,只停留在第一張圖片上。JavaScript在IE,.data中不起作用? setInterval的?

有什麼建議嗎?我記得在某個地方閱讀setInterval可能導致IE中的問題。

考慮:

$(function() { 
    var fElement = $('.fadein'); 
    fElement.find('img:gt(0)').hide(); 
    setInterval(function() { 
     if (!fElement.data('paused')) { 
      fElement.find(':first-child') 
       .stop(true, true) // fixes le tabbed/hidden animation queue 
       .fadeOut() 
       .next('img') 
       .fadeIn() 
       .end() 
       .appendTo('.fadein'); 
     } else { 
      console.log('waiting...'); 
     } 
    }, 2000); 
    $('map').hover(
     function() { 
      console.log('pausing'); 
      fElement.data('paused', 1); 
     }, 
     function() { 
      console.log('unpausing'); 
      fElement.data('paused', 0); 
     } 
    ); 
}); 
if (!console && !console.log) { 
    console = {}; 
    console.log = function() {}; 
} 

和CSS:

.fadein { 
display: block; 
height: 49px; 
width: 287px; 
float: left; 
} 
.fadein img { 
position:absolute; 
} 
.stripContainer { 
display:block; 
height: 49px; 
} 

和HTML:

<div class="fadein"> 
    <img src="img1.jpg" border="0" width="287" height="49" alt="" style="" id="level2Menu"/> 
    <img src="img2.jpg" border="0" width="287" height="49" alt="" style="" id="level2Menu"/> 
</div> 
<div class="stripContainer"> 
    <img src="img3.jpg" usemap="#secondM" border="0" width="385" height="49" alt="" style="float:left;" id="level2Menu"/> 
    <img src="img4.jpg" usemap="#secondM" border="0" width="288" height="49" alt="" style="float:right;" id="level2Menu"/> 
</div> 

編輯:這撥弄顯示它的工作,因爲它應該在Chrome:http://jsfiddle.net/8f5uU/

+5

如果您想到問題的真實標題,您可能會獲得更多幫助。 –

+2

jQuery 2.X版本不支持IE <9。 – Teemu

+0

@CoreyOgburn我不知道該怎麼稱呼這個問題,我試過console.log'ing,我無法找到問題所在。這實際上是一個IE/JS問題。 – Myles

回答

0

那麼,setInterval不應該在早期版本的IE中導致任何問題。但是,jQuery可能。正如jQuery Doc:

邊緣規定:(電流 - 1)和電流

火狐:(電流 - 1)和電流

Internet Explorer中:9+

它繼續說:

如果你需要支持舊的瀏覽器,如Internet Explor呃6-8,Opera 12.1x或Safari 5.1+,使用jQuery 1.12

嘗試使用舊版本的jQuery,看看它是怎麼回事。

+1

拍攝,我沒有意識到這個問題是2歲... –