我创建了一个div的循环,页面上有一些无线电按钮
每个单选按钮对应于一个div。因此,如果环路位于位置2,则选择无线电2,以此类推。反之亦然,如果选择无线电3,则div 3将被选中,类似于双向绑定。
function anim_loop(index) {
if(timer){
$elements.filter('.current').stop(true, true).hide().removeClass('current');
clearTimeout(timer)
}
$radios.eq(index).prop('checked', true);
$elements.eq(index).stop(true, true).addClass('current').fadeIn(1000, function() {
var $self = $(this);
timer = setTimeout(function() {
$self.fadeOut(1000).removeClass('current');
anim_loop((index + 1) % $elements.length);
timer = undefined;
}, 3000);
});
}
我也有一个左和右按钮在页面上,这也操纵循环。
有两个特定的错误是我无法修复的:
http://jsfiddle.net/69nk3/
发布于 2014-02-22 12:28:37
这是因为你要发送4作为索引。
在anim_loop函数的开头添加一个检查。
function anim_loop(index) {
if(index == $elements.length){
index = 0;
}
http://jsfiddle.net/69nk3/3/
https://stackoverflow.com/questions/21953287
复制相似问题