jQuery文本淡出/从一种文本过渡到另一种? [英] jQuery text fade/transition from one text to another?
问题描述
jQuery显然可以轻松地淡入/淡出文本.但是,如果您想将文本从一件事更改为另一件事呢?过渡会发生这种情况吗?
jQuery can obviously fadeIn/fadeOut text easily. But what if you want to change the text from one thing to another? Can this happen with a transition?
示例:
<div id='container'>Hello</div>
是否可以将文本 Hello 更改为 World ,但可以通过过渡(例如淡入淡出或某种效果)来更改而不是立即更改吗?
Can one change the text Hello to World but have it change with a transition (like a fade or some effect) instead of changing instantly?
推荐答案
您可以使用回调,如下所示:
You can use callbacks, like this:
$("#container").fadeOut(function() {
$(this).text("World").fadeIn();
});
您可以在此处尝试,或者因为该队列的工作方式特殊情况,例如此:
You can give it a try here, or because of how the queue works in this particular case, like this:
$("#container").fadeOut(function() {
$(this).text("World")
}).fadeIn();
当 .text()
调用.jquery.com/fadeOut/"rel =" noreferrer> .fadeOut()
已完成,就在再次淡入之前.
This executes the .text()
call when the .fadeOut()
is complete, just before fading in again.
这篇关于jQuery文本淡出/从一种文本过渡到另一种?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!