4

I am trying to add a SetTimeout and animation type transition to jQuery Show / Hide call. Below is how I currently have it but am wanting to add the a specific amount of time the 'show' div remains displayed before it reverts back to the orginal #bg_dv. I also want to add animated transitions between the effects if possible.

   function tilt(){
    $("#area1").click(function(){
        $("#bg_div").hide();
        $("#bg_skew").show(); // I would like to show this Div for about 5 seconds
 // and then have original back. 
       });
    }

3 Answers 3

9
$("#bg_div").hide(0).delay(5000).show(0);
$("#bg_skew").show(0).delay(5000).hide(0);

If you want animations, you can replace the calls to hide() and show() with something appropriate. For example fadeIn() and fadeOut().

Sign up to request clarification or add additional context in comments.

2 Comments

I don't believe this works. Without arguments, .show or .hide are not animation methods, hence .delay does not have any effect on them.
You're absolutely right. I've updated my answer to include a duration which turns them into animation methods.
2
    $("#area1").click(function(){

        $("#bg_div").fadeOut('fast',function(){
             $("#bg_skew").delay(5000).fadeIn('fast');
        });


    });

In order to prevent caching of multiple clicks and have the animation play many times you should also take a look at

.stop(true,true)

before any animation.Also take a look at this animation option - property.

{cache:false}

Comments

2

it's so simple. just put milliseconds in show.delay(5000) it will delay it for 5 seconds.

syntax:

$(selector).delay(speed)

speed: time in millsecnds e.g. 5000 for 5 seconds.

$(selector).show(speed,easing,callback)

speed: here put time in milliseconds like 1000 for 1 second.

easing: it defins speed of elements at different points i.e. "linear" "swing".

callback: here you can put your function it will execute after completing show method. For example when you will click button to show image after showing image it will exexcute funxtion e.g. .show(1000,function(){alert("hello")};);

Hope i helped you.

2 Comments

It doesn't delay the execution. The duration of the animation will be 5 seconds.
ohh yes. sorry my mistake thanx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.