Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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/7/css/40.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 查找当前幻灯片div并添加类_Javascript_Jquery_Slider_Jssor - Fatal编程技术网

Javascript 查找当前幻灯片div并添加类

Javascript 查找当前幻灯片div并添加类,javascript,jquery,slider,jssor,Javascript,Jquery,Slider,Jssor,我正在尝试将类添加到当前的Slider div中,我正在使用,我已经尝试在下面给出JS,以便将类添加到当前的幻灯片中,但它不起作用。我已经在Jssor调用中使用了这个JS jsor下面的调用: (演示)请 将类添加到当前幻灯片时,当前幻灯片应为红色,但它不起作用,无法找到当前幻灯片(有时会查找几分钟),但问题出在哪里? 正在尝试查找当前幻灯片div,并正确添加类。 更多信息: 这个JS很好,没有随机转换:demo 但当我添加了随机转换代码时,它无法将类添加到当前div。 请比较:

我正在尝试将类添加到当前的Slider div中,我正在使用,我已经尝试在下面给出JS,以便将类添加到当前的幻灯片中,但它不起作用。我已经在Jssor调用中使用了这个JS


jsor下面的调用:


(演示)
将类添加到当前幻灯片时,当前幻灯片应为红色,但它不起作用,无法找到当前幻灯片(有时会查找几分钟),但问题出在哪里?
正在尝试查找当前幻灯片
div
,并正确添加类。

更多信息:
这个JS很好,没有随机转换:demo
但当我添加了随机转换代码时,它无法将类添加到当前div。

请比较:
没有随机转换演示:
随机转换演示:(无法将类添加到当前div)

提前谢谢。
有两个问题:

首先:您正在将类
current
应用于错误的
div
(应用于最内层),这就是为什么在随机转换时,有时只有一部分(最内层的图像)受到影响

jssor的映像结构有很多嵌套的div,您需要在dom中查找正确的div

因此,只需将变量currentDiv更改为:

var currentDiv = currentImage.closest('#slider1_container').children("div");
这将在jssor滑块中找到第一个嵌套的
div
,您希望在那里添加类
current

第二步:要了解幻灯片是否发生更改,您需要使用
$EVT_STATE_CHANGE
检查
idleBegin
idleEnd
;不要使用
$EVT\u PARK

jssor_slider1.$On( $JssorSlider$.$EVT_STATE_CHANGE , function(slideIndex, progress, progressBegin, idleBegin, idleEnd, progressEnd){

    // add 'current' class to slide
    if(progress==idleBegin){
        var allImages = $(jssor_slider1.$Elmt).find("img[u=image]");
        var currentImage = allImages.eq(slideIndex);
        var currentDiv = currentImage.closest('#slider1_container').children("div");
        currentDiv.addClass("current");          
    }
    // remove 'current' class from slide
    else if(progress==idleEnd){
        $(jssor_slider1.$Elmt).find(".current").removeClass("current");  
    }
});

检查更新的

好主意,但问题是当它第二次滑动时,意味着从第一张幻灯片重新开始
。当前的
类已删除,意味着有一段时间它将添加,而有一段时间无法添加。请检查:(我已经减少了幻灯片项目的数量以便更好地理解)我已经删除了
$ChessMode
转换,但是类添加了一些时间,它在没有新的转换公园的情况下被删除,并且没有添加单个图像的父div:请签入检查元素:但是,当前类在滑出之前被删除。当前课堂应保留当前幻灯片,直到它可见。我已更新了答案,现在应该可以了,因为你假装你的问题包含了我的解决方案谢谢@Aariba
var currentDiv = currentImage.closest('#slider1_container').children("div");
jssor_slider1.$On( $JssorSlider$.$EVT_STATE_CHANGE , function(slideIndex, progress, progressBegin, idleBegin, idleEnd, progressEnd){

    // add 'current' class to slide
    if(progress==idleBegin){
        var allImages = $(jssor_slider1.$Elmt).find("img[u=image]");
        var currentImage = allImages.eq(slideIndex);
        var currentDiv = currentImage.closest('#slider1_container').children("div");
        currentDiv.addClass("current");          
    }
    // remove 'current' class from slide
    else if(progress==idleEnd){
        $(jssor_slider1.$Elmt).find(".current").removeClass("current");  
    }
});