Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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 setInterval-如果元素具有类externd interval_Javascript_Jquery_Setinterval - Fatal编程技术网

Javascript setInterval-如果元素具有类externd interval

Javascript setInterval-如果元素具有类externd interval,javascript,jquery,setinterval,Javascript,Jquery,Setinterval,您好,我使用以下函数,该函数每10秒加载一次javascript,并更改某些元素的可见性: function folienwechsel(){ if ($("section:last-child").hasClass('active') ) { $("section.active").hide(); $("section.active").removeClass("active").prevUntil("first").show().add

您好,我使用以下函数,该函数每10秒加载一次javascript,并更改某些元素的可见性:

function folienwechsel(){
    if ($("section:last-child").hasClass('active') ) {
            $("section.active").hide();
            $("section.active").removeClass("active").prevUntil("first").show().addClass("active");
    } else {
            $("section.active").hide();
            $("section.active").removeClass("active").next().show().addClass("active");             
    };
}

setInterval(function(){
folienwechsel()}, 10000)
现在我想扩展它来扩展一个间隔,如果一个元素有一个像“video”这样的类。你有什么建议怎么做


感谢您的帮助

您可能需要尝试以下方法:

var myInterval;

function folienwechsel() {
    if ($("section:last-child").hasClass('active')) {
        $("section.active").hide();
        $("section.active").removeClass("active").prevUntil("first").show().addClass("active");
    } else {
        $("section.active").hide();
        $("section.active").removeClass("active").next().show().addClass("active");
    };


    if ($("section:last-child").hasClass('video')) {
        clearInterval(myInterval);
        myInterval = setInterval(function() {
                folienwechsel()
            }, 2000) //Updated interval
    } else {
        //In other scenarios you may need to reset it.
        myInterval = setInterval(function() {
            folienwechsel()
        }, 10000)
    }
}
myInterval = setInterval(function() {
    folienwechsel()
}, 10000);

它如何回答有关
视频
的问题?
if($(“section:last child”).hasClass('video')){
如果元素有类视频,那么它将清除先前的间隔并创建一个新的间隔,你不是在寻找这个东西吗?这是复制粘贴错误,已经更新了我的答案:)看一看,如果发现任何问题,一定要让我知道。:)你不必将函数包装在匿名函数中。只需像这样传递它:
setInterval(folienwechsel,10000);