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图像幻灯片随机显示图像_Jquery_Slideshow - Fatal编程技术网

Jquery图像幻灯片随机显示图像

Jquery图像幻灯片随机显示图像,jquery,slideshow,Jquery,Slideshow,我正在使用链接中的幻灯片放映: 。 我需要的第一个图像也是一个随机的。 我给所有像“兰德”这样的李老师上了同样的课 var curr=$('div.rotator ul li.rand'); var rc= Math.floor(Math.random() * curr.length); var current=$(curr[rc]); 但是我下一步要做什么…请帮忙 您可以使用James Padolsey提供的这个很棒的JQuery shuffle插件来随机化LI元素的顺序 我最近在一个项目中

我正在使用链接中的幻灯片放映:

。 我需要的第一个图像也是一个随机的。 我给所有像“兰德”这样的李老师上了同样的课

var curr=$('div.rotator ul li.rand');
var rc= Math.floor(Math.random() * curr.length);
var current=$(curr[rc]);

但是我下一步要做什么…请帮忙

您可以使用James Padolsey提供的这个很棒的JQuery shuffle插件来随机化LI元素的顺序

我最近在一个项目中使用了它,它非常适合我的需要

另外,它的来源非常容易阅读(因此更容易理解)

要在幻灯片中使用它,可以使用MarkAlsup提供的JQuery Cycle插件。先洗牌dom,然后运行幻灯片:

<script>  
 $(document).ready(function() {
    $('.slideshow img').shuffle();
    $('.slideshow').cycle({
        fx: 'fade' 
    });

});
</script>

$(文档).ready(函数(){
$('.slideshow img').shuffle();
$('.slideshow')。循环({
外汇:“褪色”
});
});

这里是另一个jQuery插件,它也做同样的事情:

正在进行您提供的演示,您可以在此处下载

请确保遵循代码中的说明

//Un-comment the 3 lines below to get the images in random order

var sibs = current.siblings();
var rndNum = Math.floor(Math.random() * sibs.length );                      
var next = $( sibs[ rndNum ] );
然后在下面,您的“文档准备”部分将如下所示:

$(document).ready(function() {      
    //Load the slideshow
    $('div.rotator ul').shuffle();

    theRotator();
    $('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE
});

您用于幻灯片放映的代码太多。这可以做得简单得多。请看此随机图像幻灯片示例:

粘贴在此处供参考的代码:

<!doctype html>
<html>
  <head>
    <title></title>
    <style type="text/css">
    #slideshow-container { height:90px; position:relative; }
    #slideshow-container img { position:absolute; left:0; top:0; width:100%; height:100% }
    #slideshow      { position:absolute; left:0; top:0; width:100%; height:100%; list-style:none }
    #slideshow img  { width:120px; height:90px; background-repeat:none; background-position:top left; position:absolute; left:0; top:0 }
    #slideshow      { position:absolute; left:0; top:0; width:100%; height:100%; }
    #slideshow img  { width:120px; height:90px; background-repeat:none; background-position:top left; position:absolute; left:0; top:0 } /* adjust this for your images */
    </style>
  </head>
  <body>

    <div id="slideshow-container">
      <div id="slideshow"> 
          <img src="http://dummyimage.com/120x90/f00/fff.png&text=Image+1"> 
          <img src="http://dummyimage.com/120x90/0f0/fff.png&text=Image+2">
          <img src="http://dummyimage.com/120x90/00f/fff.png&text=Image+3">
          <img src="http://dummyimage.com/120x90/ff0/000.png&text=Image+4">
          <img src="http://dummyimage.com/120x90/0ff/fff.png&text=Image+5">
      </div> 
    </div>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">
        //extending jQuery with ':random' selector, best put into separate plugin js file
        jQuery.jQueryRandom = 0;
        jQuery.extend(jQuery.expr[":"],
        {
            random: function(a, i, m, r) {
                if (i == 0) {
                    jQuery.jQueryRandom = Math.floor(Math.random() * r.length);
                };
                return i == jQuery.jQueryRandom;
            }
        });        
        //end :random extend

        $(function() {
          $('#slideshow img').not(':random').hide(); //hide all images except one initially
          setInterval(function(){
            $('#slideshow img:visible').fadeOut('slow')
              .siblings('img:random').fadeIn('slow') //find a random image
               .end().appendTo('#slideshow');}, 
            2000); //2 second interval
        });
    </script>
  </body>
</html>

#幻灯片容器{高度:90px;位置:相对;}
#幻灯片显示容器img{位置:绝对;左侧:0;顶部:0;宽度:100%;高度:100%}
#幻灯片放映{位置:绝对;左侧:0;顶部:0;宽度:100%;高度:100%;列表样式:无}
#幻灯片放映img{宽度:120px;高度:90px;背景重复:无;背景位置:左上;位置:绝对;左:0;顶部:0}
#幻灯片放映{位置:绝对;左侧:0;顶部:0;宽度:100%;高度:100%;}
#幻灯片放映img{宽度:120px;高度:90px;背景重复:无;背景位置:左上;位置:绝对;左:0;上:0}/*为您的图像调整此选项*/
//使用“:random”选择器扩展jQuery,最好放在单独的插件js文件中
jQuery.jQueryRandom=0;
extend(jQuery.expr[“:”],
{
随机:函数(a,i,m,r){
如果(i==0){
jQuery.jQueryRandom=Math.floor(Math.random()*r.length);
};
返回i==jQuery.jQueryRandom;
}
});        
//结束:随机扩展
$(函数(){
$('#slideshow img')。不是(':random').hide();//隐藏除一个图像外的所有图像
setInterval(函数(){
$(“#幻灯片显示img:visible”).fadeOut('slow')
.sides('img:random').fadeIn('slow')//查找随机图像
.end().appendTo(“#幻灯片放映”);},
2000);//2秒间隔
});

我想补充一点,如果您可以在将其呈现为HTML之前从服务器上随机选择,那就更好了。我希望使用此解决方案,但jQuery 1.9.1的解决方案已经失败:(to ramdon start//Load the slideshow$('div.rotator ul li').shuffle();