Abdul Jamal
Abdul Jamal

Reputation: 11

how to use show() and hide() with delay()?

i want to show an image for a period of time after clicking a button and, while the image is showing, i want to hide the button. here is my code

function showimage(button, image, imagesrc){
    $(button).click(function(){
        if ($('img#'+image).length === 0) {
            $('<img id=' + image + ' src=' + imagesrc + ' style={display: none;}>').insertBefore(button);
        }

        $(button).hide();

        $('img#'+image).slideDown(500).delay(2000).slideUp(500);

        $(button).show();
    });
};

but show() and hide() won't follow the delay, what should i do?

Upvotes: 0

Views: 264

Answers (1)

Fernando Freitas Alves
Fernando Freitas Alves

Reputation: 3777

You must use delay before show.

    $(button).delay(500).show(0);

    $(button).delay(500).hide(0);

Upvotes: 3

Related Questions