0

I'm trying to excute a code right after loading the page.

The "SetInterval" won't do it:\

This is the code:

var inter1;
function start() {

    inter1 = setInterval(function() {
        counter++;
        slidernum = '#slider' + counter;
        imgnum = '#img' + counter;
        $('body').children(slidernum).fadeIn(1500);

    }, 2000);
}

start();

I also tried to wrap it with a function but it's still loading after 2000 milliseconds.

Any help or alternatives? Thanks!

1 Answers1

2

You can achieve it this way.

var inter1;
function innerStart() {

        counter++;
        slidernum = '#slider' + counter;
        imgnum = '#img' + counter;
        $('body').children(slidernum).fadeIn(1500);

}

function start() {
    innerStart();
    inter1 = setInterval(innerStart,2000);
}
pavan kumar
  • 408
  • 5
  • 19
void
  • 36,090
  • 8
  • 62
  • 107