I'm no expert on this subject, but I am going to be working
on almost
the same exact thing pretty soon. I have had a few rough
ideas about
how an "autoplay" function like that might be
approached.
First of all, just to explain why I think the JavaScript you
wrote
isn't working is that the "for" loop is
probably executing through all
9 of its iterations in about 1 millisecond. This is
because there is
nothing telling the "for" loop to
"wait" until X seconds (or whatever)
have passed until the next iteration of the loop is
executed.
Unfortunately, JavaScript has no "wait()" method
like Java does.
It's been several years since I have done any
"real" JavaScript coding
(just getting back into it), so I'm not certain about the
best way to
handle this by current standards. But I do know that
JavaScript has a
built-in method named: setTimeout(); and there is also a
method named
setInterval(); So, perhaps something like the approach
outlined in the
below code would work?
Note that the below is not in the context of the
"behavior" library at
all since I just downloaded it. I also have no idea about
what methods
are available in the Slideshow since I haven't used it at
all yet
either. The below script just uses the code that was inside
your "for"
loop (above) to "go to the next slide". I have
no idea whether that is
the correct code or not to do that.
I will present the below concept in the terms of a highly
simplified
HTML document. Obviously, this is totally untested garbage.
But it just
might help to explain the approach that I was going to try
implementing. Obviously, this would need to be completely
recoded to
exist within the prototype.js/behavior.js paradigm. This is
jsut to
illustrate (hopefully accurately) how one might deal with
executing
recurring code after a delay and being able to turn that
recurrence on
and off.
###BEGIN HTML FILE###
<html>
<head>
<script type="text/javascript">
//AutoPlay on or off by default (on == true)
var autoPlayOn = true;
//delay (in milliseconds) for autoplay transition
var autoPlayDelay = 3000;
// this function will be called by the
"timeouts" we
// create to automatically advance the slideshow
function advanceSlideshow() {
if (autoPlayOn == true) {
// code to advance to next slide
// (hopefully the below two lines of code are what
is needed)
var myPhoto = new Slideshow(photoId);
myPhoto.nextPhoto();
// create a new Timeout for the next
advanceSlideshow() call
myTimeout1 = setTimeout(advanceSlideshow,
autoPlayDelay);
} else {
//kill the timeoute
clearTimeout(myTimeout1);
}
}
// this function will be used to turn autoplay on and off
// this is sort of like a combined start/stop function
function toggleAutoPlay() {
if autoPlayOn == true) {
//kill the currently executing timeout
clearTimeout(myTimeout1);
//toggle the paused boolean
autoPlayOn = false;
} else {
autoPlayOn = true;
myTimeOut1 = setTimeout(advanceSlideshow,
autoPlayDelay);
}
}
// create a new "timeOut" to get the autoplay
started
// this will execute "advanceSlideshow()"
// after "autoPlayDelay" milliseconds have
passed.
// this could more safely be invoked on body load instead
// of just inline like this.
if (autoPlayOn == true) {
myTimeout1 = setTimeout(advanceSlideshow,
autoPlayDelay);
}
</script>
</head>
<body>
<!-- ALL OF THE SLIDESHOW HTML CODE COULD BE HERE -->
<!-- and here is a link that could "toggle"
the autoplay -->
<a href="#"
onclick="toggleAutoPlay();">Toggle
Autoplay</a>
</body>
</html>
###END HTML FILE###
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Behaviour Javascript Library"
group.
To post to this group, send email to behaviour googlegroups.com
To unsubscribe from this group, send email to
behaviour-unsubscribe googlegroups.com
For more options, visit this group at http://group
s.google.com/group/behaviour
-~----------~----~----~----~------~----~------~--~---
|