ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Listener blocking my transition #114

Closed Ryan-321 closed 9 years ago

Ryan-321 commented 9 years ago

$(".pieceContainer" ).on( "click" , function() { $( this ).addClass( "flip" ); });

$(".pieceContainer" ).on( "click" , compareFlipped );

Calling two listeners. The 2nd listener's call to compareFlipped is blocking the transition I have when I add the class flip in the first listener. is there a way to delay this or allow the transition to finish? compareFlipped below if u need

function compareFlipped() {

var flipped = $( ".flip" );

if(flipped.length == 2) { var flipOne = $( ".flip .pieceBack" ).eq(0).attr("data-id");

var flipTwo = $( ".flip .pieceBack" ).eq(1).attr("data-id");

if(flipOne == flipTwo) {
  $( ".flip" ).addClass( "stayFlipped" );
} else if (flipOne != flipTwo ) {
  $( ".pieceContainer" ).removeClass( "flip" );
}

} }

andrewsunglaekim commented 9 years ago

you could activate the event listener for compareFlipped after you do $( this ).addClass( "flip" );

Ryan-321 commented 9 years ago

tried it: $(".pieceContainer" ).on( "click" , function() { $( this ).addClass( "flip" ); $(".pieceContainer" ).on( "click" , compareFlipped ); });

and $(".pieceContainer" ).on( "click" , function() { $( this ).addClass( "flip" ); compareFlipped(); });

both had same effect.

Ryan-321 commented 9 years ago

No worries on this one, got it too work. used setTimeout