Hai Tien
Hai Tien

Reputation: 3117

Hide div after slidetoggle 5s

I use slideToggle to open and hide div as you see below.

$(document).ready(function(){
    $('.btnopencart').click(function() {
        $('#shoppingCart').slideToggle( "fast", function() {

        });
    });
});

But I want to set 5s for display #shoppingCart and of course it can toggle again although it is 'display:none' or 'display:block'

Thank you very much.

Upvotes: 2

Views: 297

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167172

Use .delay() and $(this):

$(document).ready(function(){
  $('.btnopencart').click(function() {
    $('#shoppingCart').slideToggle( "fast", function() {
      $(this).delay(5000).slideToggle("fast");
    });
  });
});

Upvotes: 4

Related Questions