Automated Rotating Divs - each at different speeds
Hi,
I'd appreciate some assistance on some JQuery code (I'm a newbie with JQuery).
What I'm trying to do is have divs with the same class name rotate. The divs overlap each other, with only one displaying at a time. Basically, I'm building an ad rotator.
Here's my working code.
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Working Test</title>
- <script type="text/javascript" src="jquery.js"></script>
- <style type="text/css">
- <!--
- .offer-holder {
- border: 1px solid red;
- width: 200px;
- height: 200px;
- background: #999;
- position: absolute;
- top: 100px;
- left: 100px;
- }
-
- .SecondsPerRotation" {
- display: none;
- }
- -->
- </style>
- </head>
-
- <body>
- <div class="rotate">
- <div class="offer-holder">1<span class="SecondsPerRotation">5</span></div>
- <div class="offer-holder">2<span class="SecondsPerRotation">3</span></div>
- <div class="offer-holder">3<span class="SecondsPerRotation">7</span></div>
- <div class="offer-holder">4<span class="SecondsPerRotation">3</span></div>
- <div class="offer-holder">5<span class="SecondsPerRotation">4</span></div>
- <div class="offer-holder">6<span class="SecondsPerRotation">6</span></div>
- </div>
-
- <script type="text/javascript">
- <!--
- var speed = 3000;
-
- $("div.rotate div").hide().eq(1).show();
- function rotate(){
- var i = $("div.rotate div:visible").prevAll("div").length + 1;
- i = i % $("div.rotate div").length;
- $("div.rotate div").fadeOut().eq(i).fadeIn();
- setTimeout("rotate()", speed);
- };
- rotate();
- //-->
- </script>
- </body>
- </html>
This works fine.
The final task is to set the speed for the rotations. Though the divs have the same name ("offer-holder"), the speeds may differ. For example, the first div may be 5 secs, the second one 10 secs, the third one 7 secs, and so on. The variable for the time ("SecondsPerRotation") is carried over from another page (I've not gotten far enough to write how to capture the variable yet).
I'm unsure how to modify the above code, so that it has the right time for each div. If I set it to "SecondsPerRotation", it uses that for all of them. I think what I want is something like - speed equals div.rotate div SecondsPerRotation value.
Any help is appreciated.
Thanks.
Stephen