2011-04-25 12 views
0

我用代碼從這裏jquery prepend + fadeInjQuery。在前面加上淡入(錯誤)

沒有fadeIn它的工作原理

function updateResult(data) { 
$('#test').prepend(
    html 
); 
} 

但隨着fadeIn作品,只有當數據包含一個div標籤,

$('#test').prepend(
    $(html).hide().fadeIn('slow') 
); 

否則FireFox返回錯誤

uncaught exception: [Exception... "Could not convert JavaScript argument arg 0 [nsIDOMViewCSS.getComputedStyle]" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: http://code.jquery.com/jquery-latest.min.js :: <TOP_LEVEL> :: line 16" data: no] 

如何重寫這段代碼?

Upd。 在我的情況我已經解決了這種方式

data = data.replace(/(?:(?:\r\n|\r|\n)\s*)/gi, ''); 
$(data).hide().prependTo('#test').fadeIn('slow'); 

脫離線後打破作品應該

回答

1

試試這個:

$(html).hide().prependTo('#test').fadeIn('slow'); 

你可能不能使用動畫的方法時,該元素是沒有添加到DOM。

+0

同樣的錯誤:((( – Tuco 2011-04-25 23:46:19

+0

@Tuco:那是別的東西,因爲它在Firefox爲我的作品:http://jsfiddle.net/fkling/duM7a/你也可以嘗試改變調用順序:'$(html).prependTo('#test')。hide()。fadeIn('slow');'雖然這可能會導致閃爍 – 2011-04-25 23:48:24

+0

也許這是CSS的東西,因爲你的代碼沒有使用它,我的錯誤和錯誤有nsIDOMViewCSS.getComputedStyle – Tuco 2011-04-25 23:52:00

1

在Firefox和Chrome中測試此代碼。我還沒有與AJAX測試:

HTML

<div id="be-images"> 
    <ul> 
     <li>lista</li> 
    </ul> 
</div> 
<button type="button">button</button> 

JQUERY

$('button').click(function(){ 
$('#be-images ul').prepend(
    $('<p>response</p>').hide().fadeIn(2000) 
); 
});