Last active
December 14, 2015 21:59
-
-
Save bittersweetryan/5154920 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create a var for tracking if the element | |
//is currently moving or not | |
var moving = false; | |
$('a').on('click', function(){ | |
var moveMe = $('#moveMe'); | |
//if the element is moving clear the queue | |
//and stop the animation | |
if( moving ){ | |
moveMe.clearQueue(); | |
moveMe.stop(); | |
//reset the moving variable | |
moving = false; | |
$(this).text('Start Animating'); | |
return; | |
} | |
$(this).text('Stop Animating'); | |
//set the moving variable to true | |
moving = true; | |
//queue the animations | |
moveMe.slideUp(1500,updateQueueCount) | |
.slideDown(1500,updateQueueCount) | |
.slideUp(1500,updateQueueCount) | |
.slideDown(1500,function(){ | |
//in the last animation's callback | |
//reset moving to false | |
moving = false; | |
updateQueueCount(); | |
}); | |
updateQueueCount(); | |
}); | |
function updateQueueCount(){ | |
$('#count').text( | |
$('#moveMe').queue('fx').length | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment