Dan Lee
Dan Lee

Reputation: 704

Fade out div before leaving page using JQuery

I'm trying to fade out some div elements with a class of .card when I click on a link before going to that link. The fade out works but I don't get taken to the linked page. Any ideas what I'm doing wrong?

$(document).ready(function() {

  $("a").click(function(event){
      event.preventDefault();
      linkLocation = this.href;
      $('.card').addClass('fadeOutDown', function() {
        window.location = linkLocation;
      });
  });

});

Upvotes: 0

Views: 895

Answers (1)

pavanjoshi
pavanjoshi

Reputation: 240

addClass signature is wrong. Try this:

    $(document).ready(function() {
      $("a").click(function(event){
          event.preventDefault();
          linkLocation = this.href;  
         $('.card').addClass('fadeOutDown').delay(1000).queue(function(){
           window.location = linkLocation;
        });
      });
    });

Upvotes: 2

Related Questions