假设我得到了这个小小的span
,我无法从其结构中进行修改或提供任何周围的元素。就是这样。但是现在我想在其中显示另一个文本,并且希望它们彼此切换。
示例:第一个文本停留1秒钟->它逐渐淡出,其他文本将显示->重复到无穷大。
是否可以仅使用toggle()函数将其存档?我尝试了一下,但没有任何效果。
$(function() {
$('#test').delay(1000).fadeOut(750, function() {
$(this).text('Some other text!').fadeIn(500);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<span id="test">This Text!</span>
您可以这样做。
希望这对您有帮助
setInterval(function() {
$("#test").fadeOut(750, function() {
if ($(this).text() == "This Text!") {
$(this).text("Some other text!").fadeIn(500);
} else {
$(this).text("This Text!").fadeIn(500);
}
});
}, 1500);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<span id="test">This Text!</span>