Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/480.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 图像导航无限循环_Javascript_Html_Loops - Fatal编程技术网

Javascript 图像导航无限循环

Javascript 图像导航无限循环,javascript,html,loops,Javascript,Html,Loops,这是我的左右导航代码。 如何在此中添加无限循环: if (i < this.sindex) { //slide to right _old.addClass('right'); setTimeout(function () { _old.removeClass('right sel anim') }, 300); _new.removeClass('anim right').addClass('sel left'); setTimeo

这是我的左右导航代码。 如何在此中添加无限循环:

if (i < this.sindex) { //slide to right
    _old.addClass('right');
    setTimeout(function () {
        _old.removeClass('right sel anim')
    }, 300);
    _new.removeClass('anim right').addClass('sel left');
    setTimeout(function () {
        _new.addClass('anim').removeClass('left')
    }, 5);
} else if (i > this.sindex) { //slide to left
    _old.addClass('left');
    setTimeout(function () {
        _old.removeClass('left sel anim')
    }, 300);
    _new.removeClass('anim left').addClass('sel right');
    setTimeout(function () {
        _new.addClass('anim').removeClass('right')
    }, 5);
}
if(ithis.sindex){//向左滑动
_old.addClass('left');
setTimeout(函数(){
_old.removeClass('left sel anim'))
}, 300);
_new.removeClass('anim left').addClass('sel right');
setTimeout(函数(){
_new.addClass('anim')。removeClass('right'))
}, 5);
}

这是一个sumogallery插件,没有无限循环功能。

不确定您是否正在使用任何插件。但是,您可以轻松实现自己的无限导航。 为了以非阻塞方式无限循环,您可以使用
setTimeout
并递归调用处理程序

无限循环实现:

类无限运算符{
构造函数(arr、处理程序、选项){
this.arr=arr;
该指数=0;
this.options=选项;
this.handler=handler;
this.t1=null
此参数为0.t2=null
}
重现{
var=这个;
如果(此索引<此阵列长度){
this.t1=setTimeout(this.handler(this.arr[this.index]),0);
这个.索引++
if(this.options&&this.options.circular&&this.index==this.arr.length){
该指数=0;
}
this.t2=设置超时(函数(){
那,重现
}, 0);
}
}
运行(){
这个
}
停止(){
clearTimeout(this.t1)
clearTimeout(this.t2)
}
}
常量数组=[1,2,3,4,5]
const IL=new InfiniteLooper(数组,console.log,{circular:true});
IL.run()
//执行更多的代码
console.log('Non-blocking!');
log('Do some math',100*9);
常数t=setInterval(()=>{
log('每1秒再做一些数学',math.random(1,4));
}, 1000)
//10秒后停止循环
设置超时(()=>{
停止
净间隔(t)

},10000)
您卡在哪里了?可能您正在寻找setInterval()方法。文件:|