console.clear();
// our elements
var pulseText = document.querySelector('#pulse_text');
var pulse = document.querySelector('#pulse');
var bounceText = document.querySelector('#bounce_text');
var bounce = document.querySelector('#bounce');
// function for playing our pulse animation
function playPulse () {
// prevent extra clicks during animation
pulse.removeEventListener('click', playPulse);
// add the library's classes
pulse.classList.add('animated', 'pulse');
// hide the play text since we can't click during animation
pulseText.style.opacity = 0;
}
// event listener calls a function so we can prevent extra clicks
pulse.addEventListener('click', playPulse);
// function to reset after animation ends
pulse.addEventListener('animationend', function () {
// restore event listener
pulse.addEventListener('click', playPulse);
// remove library's classes so they can be placed again
pulse.classList.remove('animated', 'pulse');
// restore the text since we can now click again
pulseText.style.opacity = 1;
});
// function to play our infinite bounce animation
bounce.addEventListener('click', function () {
// check to see if library classes have been applied
if (!bounce.classList.contains('animated')) {
// animation is not playing, we will start it
// change text to explain how to stop animation
bounceText.innerText = 'click to stop';
// add the library's classes
bounce.classList.add('animated', 'bounce', 'infinite');
} else {
// animation is playing, we will stop it
// change text to explain how to start animation
bounceText.innerText = 'click to play';
// remove the library's classes
bounce.classList.remove('animated', 'bounce', 'infinite');
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.