Just bootstrapping a quick modal script and I hit the wall.
Testing css animations and all works fine. I can open a modal from a link but when I try to open same modal again straight after for some reason
.one("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd",
function(e){
modalBg.removeClass('flex fadeOut animated');
$(this).off(e);
});
is fired instantly... When I try to click different link every time it works fine. I did try to null modalBg variable and it does the trick but console return the error that removeClass is not defined. So for some reason modalBg.removeClass('flex fadeOut animated'); is still fired.
Here is JSBin
Here is the whole code:
$( document ).ready(function() {
$( ".modal-link" ).on( "click", function() {
attribute = $(this).attr('href');
attribute = attribute.replace('#','');
console.log(attribute);
$('.modal-bg[data-modal='+ attribute +']').addClass( "flex animated fadeIn" );
$('.modal-bg[data-modal='+ attribute +'] .modal').addClass( "animated fadeInDown" );
});
$('.modal-close').on('click', function() {
modalBg = $(this).closest('.modal-bg');
modalBg.removeClass('fadeIn');
modalBg.addClass('fadeOut');
modalBg.one("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd",
function(e){
modalBg.removeClass('flex fadeOut animated');
$(this).off(e);
});
});
});