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

1

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(function() {
                innerStart();
    }, 2000);
}
void
  • 34,922
  • 8
  • 55
  • 102
  • If it solves your problem please consider voting it up and marking it as correct answer. – void Feb 21 '15 at 20:55