Skip to content

Instantly share code, notes, and snippets.

@bittersweetryan
Last active December 14, 2015 21:59
Show Gist options
  • Save bittersweetryan/5154920 to your computer and use it in GitHub Desktop.
Save bittersweetryan/5154920 to your computer and use it in GitHub Desktop.
//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