0

I have a small script that changes images every 3 seconds.

I want it to change every 3 seconds but with a fade-in fade-out effect.

I also want it to display some text in the bottom of the image.

Also, can it be done with html + css only without JS?

Here is my script:

function run(interval, frames) {
    var int = 1;

    function func() {
        document.body.id = "b"+int;
        int++;
        if(int === frames) { int = 1; }
    }

    var swap = window.setInterval(func, interval);
}

run(3000, 10); //milliseconds, frames

Here is the css:

#b1 { background: hsl(0, 50%, 50%); }
#b2 { background: hsl(30, 50%, 50%); }
#b3 { background: hsl(60, 50%, 50%); }

See it in action: JSfiddle

StackBuck
  • 789
  • 1
  • 12
  • 34

0 Answers0