<h2>An animation called "reverse" won't work in shorthand</h2>
<div class="anim">
<div class="ball"></div>
<button>ANIMATE</button> <button>RESET</button>
</div>
<p>If you change the animation name to a non-reserved word, the animation will work.</p>
<p class="p">Demo by Louis Lazaris. <a href="http://www.sitepoint.com/12-little-known-css-facts-the-sequel" target="_blank">See article</a>.</p>
body {
text-align: center;
padding: 0 20px;
}
button {
margin-right: 10px;
}
.anim {
max-width: 80%;
margin: auto;
border: solid 1px;
padding: 14px;
}
.ball {
margin: 40px;
width: 75px;
height: 75px;
background: hotpink;
border-radius: 50%;
position: relative;
}
.ball-1 {
animation: reverse 2s linear forwards;
}
@keyframes reverse {
from {
left: 0;
}
to {
left: 80%;
}
}
.p {
font-family: Arial, sans-serif;
font-size: 14px;
padding-top: 130px;
}
var btn1 = document.querySelectorAll('button')[0],
btn2 = document.querySelectorAll('button')[1],
ball1 = document.querySelectorAll('.ball')[0],
ball2 = document.querySelectorAll('.ball')[1];
btn1.addEventListener('click', function () {
ball1.classList.add('ball-1');
ball2.classList.add('ball-2');
}, false);
btn2.addEventListener('click', function () {
ball1.classList.remove('ball-1');
ball2.classList.remove('ball-2');
}, false);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.