Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

javascript - 在一个简单的jQuery函数中切换(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>   ask by Bill Bronson translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...