gpt4 book ai didi

javascript - Jquery 循环 : iterate siblings by four, 然后从头开始

转载 作者:行者123 更新时间:2023-11-28 11:30:58 25 4
gpt4 key购买 nike

问:我如何创建一个循环来同时显示四个 div,它们是 #reviewswidget 的子级?一旦幻灯片放映结束,它需要返回到前四个 div。

<div id="reviewswidget">
<div class="reviewtitle">title 1 goes here</div>
<div class="reviewrating">rating 1 goes here</div>
<div class="reviewreview"> review 1 goes here</div>
<div class="reviewauthor">author 1 goes here</div>
<div class="reviewtitle">title 2 goes here</div>
<div class="reviewrating">rating 2 goes here</div>
<div class="reviewreview"> review 2 goes here</div>
<div class="reviewauthor">author 2 goes here</div>
</div>

我的尝试:

jQuery(function () {
jQuery('#reviewswidget div').hide().slice(0, 4).show();
setInterval(function () {
jQuery('#reviewswidget div').filter(':visible').fadeOut(function () {
self.setSliceIteration(4);
self.setSliceTotal(jQuery('#reviewswidget div').length);
if (self.getSlice() === 0 && self.getSlice() === '') {
jQuery('#reviewswidget div').hide().nextAll().slice(self.getSlice()).show();
self.setSlice(self.getSliceIteration() + self.getSlice());
}
if (self.getSlice() < self.getSliceTotal()) {
$(this).nextAll().slice(self.getSlice()).show();
self.setSlice(self.getSliceIteration() + self.getSlice());
}
if (self.getSlice() < self.getSliceTotal()) {
}
});
}, 3000);
});

完整代码: http://jsfiddle.net/Q3jaf/1/

最佳答案

尝试

var $chidlren = $('#reviewswidget').children().slice(4).hide();
setInterval(function(){
$('#reviewswidget').children().slice(0, 4).hide().appendTo('#reviewswidget')
$('#reviewswidget').children().slice(0, 4).show()
}, 1000)

演示:Fiddle

关于javascript - Jquery 循环 : iterate siblings by four, 然后从头开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21151455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com