如何解决Javascript引用两套文本Silder
我想用2组数据创建引号文本滑块。
小提琴链接-> https://jsfiddle.net/628r3t1h/
(function() {
var quotes = $(".quotes");
var quoteIndex = -1;
function showNextQuote() {
++quoteIndex;
quotes.eq(quoteIndex % quotes.length)
.fadeIn(1500)
.delay(1000)
.fadeOut(1000,showNextQuote);
}
showNextQuote();
})();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- set 1 -->
<h1 style="" class="sec1-head">Set 1<br/>
<span style="" class="quotes sec1-head-quotes">Text 1.1</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 1.2</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 1.3</span>
</h1>
<!-- set 2 -->
<h1 style="" class="sec1-head">Set 2<br/>
<span style="" class="quotes sec1-head-quotes">Text 2.1</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 2.2</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 2.3</span>
</h1>
此处 Set 1 应该首先运行,然后 Set 2 应该可见。而且循环必须继续。
解决方法
喜欢吗?
const sets = $(".set");
let set = sets[0],quote = 0;
sets.hide();
$(sets[0]).fadeIn(1500);
function showQuote() {
if($(set).children().eq(quote).is(':last-child')) {
if($(set).hasClass("last")) {
set = $(".set").first();
} else {
set = $(set).next();
}
sets.hide();
$(set).fadeIn(1500);
quote = 1;
} else {
++quote
}
$(set).children().eq(quote)
.fadeIn(1500)
.delay(1000)
.fadeOut(1000,showQuote);
}
showQuote();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- set 1 -->
<h1 style="" class="sec1-head set">Set 1<br/>
<span style="" class="quotes sec1-head-quotes">Text 1.1</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 1.2</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 1.3</span>
</h1>
<!-- set 2 -->
<h1 style="" class="sec1-head set last">Set 2<br/>
<span style="" class="quotes sec1-head-quotes">Text 2.1</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 2.2</span>
<span style="display: none;" class="quotes sec1-head-quotes">Text 2.3</span>
</h1>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。