Forum Moderators: open
I have a rudimentary image fader using Javascript and the Scriptaculous framework:
Event.observe(window, 'load', function() {
fadeout.delay(5.0);
fadeout2.delay(10.0);
fadeout3.delay(15.0);
});
function fadeout(){
new Effect.Fade("slideshow_container", {duration:1.5, from:1.0, to:0.0});
}
function fadeout2(){
new Effect.Fade("slideshow_container2", {duration:1.5, from:1.0, to:0.0});
}
function fadeout3(){
new Effect.Fade("slideshow_container3", {duration:1.5, from:1.0, to:0.0});
}
What I would like to do is have this start over again once it's finished. I am not sure how to go about doing that.
Any ideas?
Event.observe(window, 'load', function() {fadeout.delay(5.0);});
var n = 1;
function fadeout(){
if ( n===1 ) { ... code to unfade all ? ... }
new Effect.Fade("slideshow_container" + (n++), {duration:1.5, from:1.0, to:0.0});
if ( n===4 ) { n=1; }
fadeout.delay(5.0);
}
Event.observe(window, 'load', function() {
function hideAndShow() {
fadeout.delay(5.0, 'slideshow_container');
fadeout.delay(10.0, 'slideshow_container2');
fadeout.delay(15.0, 'slideshow_container3');
fadein.delay(20.0, 'slideshow_container');
fadein.delay(25.0, 'slideshow_container2');
fadein.delay(30.0, 'slideshow_container3');
}
hideAndShow(); // Execute once on page load
setInterval(hideAndShow, 30000); // Then repeat every 30 seconds
});
function fadeout(id){
Effect.Fade(id, {duration:1.5, from:1.0, to:0.0});
}
function fadein(id) {
Effect.Appear(id, {duration: 1.5, from: 0.00, to: 1.0});
}
I am trying to combine the two ideas. Basically what I would like to do is have the first image fade in, stay for 5 seconds, then fade out, then the same for image2, then the same for image 3 and then loop back to image1 again and so on.
I am embarrassed to admit I have been working on this for 2 days now.
Event.observe(window, 'load', function() {fadeout.delay(5.0);});
var n = 4;
function fadeout(){
// fade out prior
new Effect.Fade("slideshow_container" + (n++), {duration:1.5, from:1.0, to:0.0});
if ( n===4 ) { n=1; }
// at same time fade in next
new Effect.Fade("slideshow_container" + (n), {duration:1.5, from:0.0, to:1.0});
fadeout.delay(5.0);
}
Should be this, right?:
Event.observe(window, 'load', function() {fadeout.delay(5.0);});
var n = 4;
function fadeout(){
// fade out prior
if ( n===4 ) { n=1; }
new Effect.Fade("slideshow_container" + (n++), {duration:1.5, from:1.0, to:0.0});
// at same time fade in next
new Effect.Fade("slideshow_container" + (n), {duration:1.5, from:0.0, to:1.0});
fadeout.delay(5.0);
}