Markus Hayner
Markus Hayner

Reputation: 2959

How can I make a div to disappear after couple of seconds?

I have the following function which fade out the div on touch but I want in the same time to make it disappear after 5 seconds in case the user will not react. Any idea how shall I modify the code?

$('#ceva').on({
    'touchstart': function() {
        $('#ceva').fadeOut();
    }
});

Upvotes: 0

Views: 63

Answers (2)

Tushar
Tushar

Reputation: 87203

Use delay with touchend as follow.

Set a timer to delay execution of subsequent items in the queue.

$('#ceva').on({
    'touchstart': function() {
        $('#ceva').fadeOut();
    }
});

In ready add following:

$('#ceva').delay(5000).fadeOut();

Upvotes: 2

Chander .k
Chander .k

Reputation: 541

Please try this.

$(function() {
    setTimeout(function() {
        $("#ceva").hide('blind', {}, 500)
    }, 5000);
});

Upvotes: 0

Related Questions