I have a div containing a photo that a user clicks on to reveal a name. I've set up a snazzy flip effect for this reveal. On the next click, a new photo and name are loaded (via ajax) to replace the old ones.
In order to provide a smooth transition, I've set it up to flip 90 degrees (i.e. become invisible), load the new set, then complete the flip to reveal the photo. Here's code that does this, running beautifully:
$name_div.one("click", function(){
$flipper.css("transform", "rotateY(270deg)") ;
// Update mastery to level 1
updateMastery(student, 1, i)
$flipper.css("transform", "rotateY(0deg)") ;
})
Only one problem... the updateMastery() function begins running before the transform has completed. This means the new name can replace the old name before it's been hidden.
$name_div.one("click", function(){
$flipper.css("transform", "rotateY(270deg)") ;
// Update mastery to level 1
$flipper.on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd',
function() {
updateMastery(student, 1, i)
});
$flipper.css("transform", "rotateY(0deg)") ;
})
This code does what I want it to do. It waits for the transition to end, then loads the new name/photo, then finishes the flip. On the first couple of clicks it runs well, but as I click and progress through the photos the script gets progressively slower and slower until eventually hanging my browser.
Any idea why the .on('transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd'...
script would do this? Is it storing something in the browser each time? Is there something I can do to prevent or clear this?
Thanks