簡體   English   中英

在一個簡單的 jQuery 函數中切換

[英]Toggling around in a simple jQuery Function

可以說我得到了這個小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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM