Last active
August 29, 2015 14:16
-
-
Save DannyDelott/684b47a7b5d458a8134b to your computer and use it in GitHub Desktop.
betterInterval Example
This file contains 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
$(function(){ | |
$content.on('click', function(){ | |
// case 1: currently playing, let's stop it | |
if(!changeQuote.stop){ | |
$content.css('background', '#ddd'); | |
changeQuote.stop = true; | |
} | |
// case 2: we've stopped it, but we're waiting for a response | |
else if(!changeQuote.stopped && changeQuote.stop) { | |
changeQuote.stop = false; | |
$content.css('background', '#eee'); | |
changeQuote(); | |
} | |
// case 3: restart the interval | |
else { | |
$content.css('background', '#eee'); | |
betterInterval(changeQuote, 5000, true); | |
} | |
}); | |
betterInterval(changeQuote, 5000, true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment