[英]Toggling around in a simple jQuery Function
Lets say I got this little span
that I can't modify from its structure or give any surrounding elements.可以说我得到了这个小
span
,我无法从它的结构中修改或提供任何周围的元素。 It is like it is.它就是这样。 But now I want to display another Text in it and I want them to toggle between each other.
但现在我想在其中显示另一个文本,我希望它们在彼此之间切换。
Example: First text stays for 1 seconds -> it gets faded out and the other text will be displayed -> repeat to infinity.示例:第一个文本停留 1 秒 -> 淡出,显示另一个文本 -> 重复至无限。
Is it possible to archive this with just the toggle() function?是否可以仅使用 toggle() 函数将其存档? I tried around a bit but nothing really works.
我尝试了一下,但没有任何效果。
$(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>
You can do it like this.你可以这样做。
Hope this will help you希望对你有帮助
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.