Flexslider从随机幻灯片开始,然后继续顺序加载 [英] Flexslider Start at a random slide and then continue loading sequentially

查看:106
本文介绍了Flexslider从随机幻灯片开始,然后继续顺序加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Flexslider- http://www.woothemes.com/flexslider/和我有一个带有37个幻灯片的滑块设置(是的,我知道这很荒谬).我需要一种在页面加载时随机选择幻灯片1和幻灯片37之间的幻灯片,然后从那里继续继续的方法.

I am using Flexslider - http://www.woothemes.com/flexslider/ and I have a slider setup with 37 slides in it (yes I know this is ridiculous). I need a way where when the page loads, it randomly picks a slide between slide 1 and slide 37, and then it continues on squentially from there.

例如:

页面加载完毕,它随机选择第17张幻灯片.在第17张幻灯片之后出现的下一张幻灯片应该是18,然后是19,然后是20,依此类推.

The page loads and it randomly picks slide # 17. The next slide to appear after slide 17 should be 18, then 19, then 20 and so on.

下次加载页面时,它会随机选择另一张幻灯片.假设这次加载了29张.下一张幻灯片应该是30张,然后是31张,然后是32张,依此类推...

The next time the page loads it randomly picks another slide. Say this time it loads 29. The next slide should be 30, then 31, then 32, etc...

到目前为止,我已经弄清楚了逻辑,因此我知道我需要一种方法让Flexslider首先计算当前滑块中的幻灯片数量.然后,我需要获取该数字,并从1到X#个幻灯片中选择一个随机数.

I have the logic figured out so far that I know I need a way to first have Flexslider count the number of slides in the current slider. Then I need to take that number and pick a random number between 1 and X # of slides in the slider.

我在Flexslider网站上找到了一些代码:

I found some code on the Flexslider site:

start: function(slider) {
  $('.total-slides').text(slider.count);
},

据我所知,可以为您提供幻灯片的数量,但是从这里我不确定如何将随机数传递给

Which I understands gives you the number of slides, but from here I'm not sure what to do to get a random number to pass to the

startAt: 0,

选项.

这是我当前的flexslider jQuery

Here is my current flexslider jquery

    jQuery( document ).ready( function( $ ) {
        $('.flexslider').flexslider({
            animation: "slide",
            useCSS: false,
            controlNav: false,
            slideshow: false,
            start: function(slider) {
                $('.total-slides').text(slider.count); // This gets the number of slides in the slider
              },
              startAt: 0, //This should be a random number
        });
    });

推荐答案

使用上述代码设置变量即可,然后可以调用该变量.

Setting a variable with your above code works, you can then call the variable.

$(window).load(function(){

$(window).load(function(){

var randomthis = Math.floor((Math.random()* $('.flexslider li').length )+1);

$('.flexslider').flexslider({
  animation: "slide",
  useCSS: false,
  controlNav: false,
  slideshow: false,
  startAt: randomthis

});

});

这篇关于Flexslider从随机幻灯片开始,然后继续顺序加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆