2011-06-04 104 views
2

我想在1秒内显示“再见”,淡入淡出,用 “hello”取代它,然后淡入。为什么不是这个snippetwork? (jQuery的 被加载):jQuery不会淡入淡出文本?

<div id="foo">x</div> 
<script type="text/javascript"> 
$('#foo').fadeOut().html('goodbye').fadeIn().delay(1000).fadeOut().html('hello').fadeIn(); 
</script> 

我正确地使用该队列中,以便出现在顺序(不异步地)这些命令,是吗?

完整版:http://test.barrycarter.info/stacked1.html

编辑:谢谢大家谁回答!我赞赏备用建议。我想我真正的问题是“为什么我的代码不工作?”我正在学习jQuery,并确定我的代码出错的地方对我真的有帮助!

回答

0

尝试把你的声明中

$(document).ready(function(){ 
    /*code here*/ 
}); 

或把它在一个函数调用该函数会

2

你想使fadeIn部分回调函数为fadeOut。所以......

$('#foo').fadeOut('slow', function(){ 
    $('#foo').fadeIn('slow').html('Hello'); 
}); 

变化slow1000 1秒或任何希望。

http://jsfiddle.net/qK26W/