Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 jQuery触摸刷对li项目的影响_Javascript_Jquery - Fatal编程技术网

Javascript jQuery触摸刷对li项目的影响

Javascript jQuery触摸刷对li项目的影响,javascript,jquery,Javascript,Jquery,我尝试使用jQuery触摸滑动来单击每个li项目。这是我的html <div class="slider-active" id="active_885"> <label for="slide1-885"></label> <label for="slide2-885"></label> <label for="slide3-885"></label> </div> 凭借我对javas

我尝试使用jQuery触摸滑动来单击每个li项目。这是我的html

<div class="slider-active" id="active_885">
<label for="slide1-885"></label>
<label for="slide2-885"></label>
<label for="slide3-885"></label>        
</div>
凭借我对javascript的一点了解,我可以让上面的脚本在向右滑动时单击第一个标签,在向左滑动时单击最后一个标签。但我想要的是让脚本按顺序单击标签(如上面我的html所示),每次向右滑动时一个接一个地向下,向左滑动时向上

希望我能解释一下。
任何帮助???

您可以创建一个
项目数组,并基于滑动重复该数组

大概是这样的:

HTML:


JavaScript:

var active885Labels = jQuery('label.swipeLabel'),
    current885Label = -1;

jQuery("#slides_885").swipe({
    swipeRight: function(event, direction, distance, duration, fingerCount) {
                    if (current885Label < active885Labels.length) {
                        current885Label++;
                        active885Labels[current885Label].click()
                    }
                    else
                    {
                        //we are already at the last label, either wrap around or do nothing, or click the last label again, or do something else
                    }
                },
    swipeLeft: function(event, direction, distance, duration, fingerCount) {
                    if (current885Label > 0) {
                        current885Label--;
                        active885Labels[current885Label].click()
                    }
                    else
                    {
                        //we are already at the first label, either wrap around or do nothing, or click the first label again, or do something else
                    }
                }
});
var active885Labels=jQuery('label.swipeLabel'),
current885Label=-1;
jQuery(“#幻灯片885”)。轻扫({
swipeRight:功能(事件、方向、距离、持续时间、手指计数){
如果(current885Label0){
当前885标签--;
active885Labels[current885Label]。单击()
}
其他的
{
//我们已经看到了第一个标签,要么环绕,要么什么都不做,要么再次单击第一个标签,或者执行其他操作
}
}
});

对不起,我的意思是:)我会试试这个,然后再告诉你:我应该在哪里定义数组?很抱歉,我对javascript了解不多:)
<div class="slider-active" id="active_885">
    <label class="swipeLabel" for="slide1-885"></label>
    <label class="swipeLabel" for="slide2-885"></label>
    <label class="swipeLabel" for="slide3-885"></label>        
</div>
var active885Labels = jQuery('label.swipeLabel'),
    current885Label = -1;

jQuery("#slides_885").swipe({
    swipeRight: function(event, direction, distance, duration, fingerCount) {
                    if (current885Label < active885Labels.length) {
                        current885Label++;
                        active885Labels[current885Label].click()
                    }
                    else
                    {
                        //we are already at the last label, either wrap around or do nothing, or click the last label again, or do something else
                    }
                },
    swipeLeft: function(event, direction, distance, duration, fingerCount) {
                    if (current885Label > 0) {
                        current885Label--;
                        active885Labels[current885Label].click()
                    }
                    else
                    {
                        //we are already at the first label, either wrap around or do nothing, or click the first label again, or do something else
                    }
                }
});