2012-07-26 19 views
0

有誰知道爲什麼下面的代碼在IE中不起作用? (在其他瀏覽器中工作不錯)逐字顯示動畫無法在IE中工作

  div.hide().contents().each(function() { 
       var words; 
       if (this.nodeType === 3) { 
        words = '<span> ' + this.data.split(/\s+/).join(' </span><span> ') + ' </span>'; 
        $(this).replaceWith(words); 
       } else if (this.nodeType === 1) { 
        this.innerHTML = '<span> ' + this.innerHTML.split(/\s+/).join(' </span><span> ') + ' </span>'; 
       } 
      }); 

      // Remove any empty spans that were added 
      div.find('span').hide().each(function() { 
       if(!$.trim(this.innerHTML)) { 
        $(this).remove(); 
       } 
      }); 

      div.show().find('span').each(function(i) { 
       $(this).css('filter', 'alpha(opacity=40)'); 
       $(this).delay(400 * i).fadeIn(600); 
      }); 

任何解決方法,以逐字顯示效果在IE中工作?

編輯:

創建一個小提琴這裏:http://jsfiddle.net/8dh3F/

+1

你在控制檯中遇到什麼錯誤?什麼不工作? – 2012-07-26 11:40:56

+0

我沒有收到任何錯誤。問題是文字根本不顯示! – 2012-07-26 11:42:50

+0

用fadeTo(1,600)代替fadeIn(600)可能會有所幫助 – Sem 2012-07-26 11:45:34

回答

0

OK我找到了一種方法來顯示在IE中逐個字母(在其他瀏覽器的工作,以及),使用lettering.js庫:

HTML標記:

<div class='intro'> 
    <div class='starthidden intro'>{{ poem.introLine1 }}</div> 
    <div class='starthidden intro'>{{ poem.introLine2 }}</div> 
    <div class='starthidden intro'>{{ poem.introLine3 }}</div> 
    <div class='starthidden intro'>{{ poem.introLine4 }}</div> 
    <div class='starthidden intro'>{{ poem.introLine5 }}</div> 
    <br> 
</div> 
<div class='verse'> 
    <div class='starthidden trait'>{{ poem.traitLine1 }}</div> 
    <div class='starthidden trait'>{{ poem.traitLine2 }}</div> 
    <div class='starthidden trait'>{{ poem.traitLine3 }}</div> 
    <div class='starthidden trait'>{{ poem.traitLine4 }}</div> 
    <div class='starthidden trait'>{{ poem.traitLine5 }}</div> 
    <br> 
</div> 
etc 

JQuery的:

var div = $('.starthidden'); 
var delay = 400; 
var fadeIn = 600; 
div.lettering(); 
div.find('span').hide(); 
div.show().find('span').each(function(i) { 
    $(this).delay(delay * i).fadeIn(fadeIn); 
}); 
0

問題是這條線。它工作在IE9但不是8或7

this.innerHTML = '<span> ' + this.innerHTML.split(/\s+/).join(' </span><span> ') + ' </span>';

它不喜歡this.innerHTML。謝天謝地,你正在使用jQuery!

用這個代替:

$(this).html(function(index, oldhtml){ 
    return '<span> ' + oldhtml.split(/\s+/).join(' </span><span> ') + ' </span>'; 
}); 
+0

你有沒有設法在IE8或IE7中工作?我只是嘗試使用IE8和文本不會出現:jsfiddle.net/Mb8gs – 2012-07-27 02:27:12

+0

我收到一個錯誤:「意外的調用方法或屬性訪問」,和代碼「{this.nodeType === 1)&&(突出顯示this.appendChild(a)}「。 – 2012-08-01 01:53:42