Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Jquery幻灯片显示if语句_Jquery_Slideshow - Fatal编程技术网

Jquery幻灯片显示if语句

Jquery幻灯片显示if语句,jquery,slideshow,Jquery,Slideshow,嗨,我需要为我的幻灯片创建一个if语句,如果只有一个图像,我不希望幻灯片处于活动状态 Javascript: <script type="text/javascript"> function slideSwitch() { var $active = $('#slideshow IMG.active'); if ( $active.length == 0 ) $active = $('#slideshow IMG:last'); // use

嗨,我需要为我的幻灯片创建一个if语句,如果只有一个图像,我不希望幻灯片处于活动状态

Javascript:

    <script type="text/javascript">



function slideSwitch() {
    var $active = $('#slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');

    // uncomment the 3 lines below to pull the images in random order

    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

</script>

函数滑动开关(){
var$active=$(“#slideshow IMG.active”);
如果($active.length==0)$active=$(“#幻灯片显示IMG:last”);
//使用此选项可以按图像在标记中的显示顺序提取图像
var$next=$active.next().length?$active.next()
:$(“#幻灯片演示IMG:first”);
//取消对下面3行的注释,以随机顺序拖动图像
//var$sibs=$active.sibles();
//var rndNum=Math.floor(Math.random()*$sibs.length);
//var$next=$($sibs[rndNum]);
$active.addClass('last-active');
$next.css({opacity:0.0})
.addClass(“活动”)
.animate({opacity:1.0},1000,function()){
$active.removeClass('active last active');
});
}
$(函数(){
设置间隔(“滑动开关()”,5000);
});
html:



JS不是我的强项,任何帮助都会很好

将您的
domready
功能更改为:

$(function() {
    if ($("#slideshow img").length > 1) {
      setInterval( "slideSwitch()", 5000 );
    }
});
$(function() {
    if ($("#slideshow img").length > 1) {
      setInterval( "slideSwitch()", 5000 );
    }
});