简体   繁体   English

定时jQuery旋转

[英]Timed jQuery rotation

I'm trying to make the selector rotate at varying times, I figured I would try a simple if/else statement, to make the first one rotate after 3 seconds, and the following ones after 30 seconds. 我试图使选择器在不同的时间旋转,我想我会尝试一个简单的if / else语句,使第一个在3秒后旋转,然后在30秒后旋转。 However, it just keeps rotating it every three seconds. 但是,它只是每三秒钟旋转一次。 Had I figured how to make this work, I was planning on adding more if/else statements inside the previous one, so that I could add custom times for each slide. 如果我想出了如何做的话,我计划在上一个语句中添加更多if / else语句,以便为每张幻灯片添加自定义时间。 Any ideas how I could achieve this? 有什么想法可以实现吗?

$(document).ready(function(){

    var flipped = false;

      if (!flipped)
      {
         $('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
         $('#Blog1 > ul').tabs('rotate', 3000, true);
         flipped = true;
      }
      else
      {
         $('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
         $('#Blog1 > ul').tabs('rotate', 30000, true);
      }
});

You're clearly setting "flipped" to false every time you run the function. 每次运行该函数时,您显然都将“ flip”设置为false。 Or rather, your not running it again to check for flipped. 或者更确切地说,您不再运行它来检查是否翻转。 (I think) (我认为)

You need to separate the variable from the function, otherwise it will always be false. 您需要将变量与函数分开,否则它将始终为false。

As for time, you can easily use Math.random() 至于时间,您可以轻松使用Math.random()

randomNumber = Math.floor((Math.random() * 30) + 1); // Random number between 1 and 30
$('#Blog1 > ul').tabs({fx:{opacity: 'toggle'}});
$('#Blog1 > ul').tabs('rotate', randomNumber, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM