0

I would like to add a wait() or delay between two functions.

function(imageID)
    {
        //alert("i main slider called ");

        if(en==1)
        {
            var selected=$('#' + sel);
            $(selected).animate({"left": "+=30px","opacity": "0.99"},"slow");
            $(selected).animate({"height":"354px","width":"295px"},30);
            $(selected).css("-webkit-transform-style","preserve-3d");
            $(selected).css("-webkit-transition","all 1.0s linear");
            $(selected).css("transform-style","preserve-3d");
            $(selected).css("transition","all 1.0s linear");
            $(selected).css("-webkit-transform","rotateY(0deg)");
            $(selected).css("transform","rotateY(0deg)");
            en=0;
        }

        if(my.circular)
        {
            /* Trigger left jumppoint */
            if(imageID+1 === my.imageFocusMax)
            {
                /* Set jump target to the same cloned image on the right */
                clonedImageID = my.max - my.imageFocusMax;
                jumpTarget = -clonedImageID * my.xStep;

                /* Set the imageID to the last image */
                imageID = clonedImageID-1 ;
            }

In my function I want to add a delar after the if statement. How can I do that? I have tried adding delay() but it is not working. What should I use?

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
anam
  • 3,905
  • 16
  • 45
  • 85
  • Check out this link http://stackoverflow.com/questions/1183872/put-a-delay-in-javascript – Santosh May 08 '13 at 12:55
  • Here is the solution http://stackoverflow.com/questions/4437600/sleep-in-jquery – Somnath Kharat May 08 '13 at 12:56
  • First Why? Then how.... – Ron van der Heijden May 08 '13 at 13:04
  • @Bondye first if condition is removing apllied css. and 2nd if is to slide image... how to use setTimeout() in my case.. – anam May 08 '13 at 13:06
  • Why you don't use callback instead of delaying the application. You want to slide image when css is removed? – Ron van der Heijden May 08 '13 at 13:56
  • @Bondye first block is to remove css which is already applied , and yes then there is series of if to slide image , Basically in my slider on selection of image i have written code to bring image in Center, enlarge and rotate image .now when user will select any other Image then i have wriitten IF(see above) to remove all css then slide second image into center. – anam May 09 '13 at 05:03
  • @simmisimmi: *"In my function I want to add a delar after the if statement."* You have more than one `if` statement in that code. Delay after which of them? Delaying which code? If you **show** us your `delay` attempt, we can probably help you. The reason you haven't gotten a useful answer is that the question is unclear. – T.J. Crowder May 09 '13 at 06:46

1 Answers1

3

Use the setTimeout function. That way you can tell the browser to wait before doing something.

Geeky Guy
  • 9,229
  • 4
  • 42
  • 62