<select>
<option value="css">CSS</option>
<option value="jquery">jQuery</option>
</select>
<button>Run animation</button>
<p>Status: <span class="status">Inactive</span></p>
<div class="container">
<div class="card">
<img src="https://imgur.com/7Q2fZcQ.png" class="back" />
<img src="https://imgur.com/G4BYZF1.png" class="front" />
</div>
</div>
body {
margin: 16px;
background-color: #27a13d;
}
select {
float: left;
padding: 0 0 0 8px;
font-size: 12px;
font-weight: bold;
font-family: 'Verdana';
height: 24px;
background-color: white;
color: #27a13d;
border: none;
border-radius: 6px;
background-color: white;
}
button {
float: left;
display: inline-block;
outline: 0;
border: none;
cursor: pointer;
border-radius: 6px;
font-size: 12px;
font-weight: bold;
font-family: 'Verdana';
height: 24px;
background-color: white;
color: #27a13d;
padding: 0 12px;
margin-left: 8px;
}
p {
margin: 0;
display: inline-block;
color: white;
font-size: 14px;
font-family: 'Verdana';
margin-left: 8px;
line-height: 24px;
}
.container {
position: relative;
margin-top: 16px;
}
.card {
position: absolute;
width: 106px;
height: 148px;
}
.card.move {
animation : move 2s;
}
.card img {
position: absolute;
width: 100%;
height: 100%;
}
.card .front {
display: none;
}
@keyframes move {
0% { left: 0 }
50% { left: 100px }
100% { left: 0 }
}
$( "button" ).click(function() {
var option = $('select option:selected').val()
if (option == "css") {
animateUsingCSS()
} else if (option == "jquery") {
animateUsingJQuery()
}
});
function animateUsingCSS() {
var cardElement = document.getElementsByClassName("card")[0];
var statusElement = document.getElementsByClassName("status")[0];
cardElement.classList.add("move");
statusElement.innerHTML = "Animating"
var animationEndCallback = function() {
cardElement.classList.remove("move");
statusElement.innerHTML = "Inactive"
}
cardElement.addEventListener("webkitAnimationEnd", animationEndCallback);
cardElement.addEventListener("oAnimationEnd", animationEndCallback);
cardElement.addEventListener("animationend", animationEndCallback);
}
function animateUsingJQuery() {
$(".status").text("Animating")
$( ".card" ).animate({
left: "100px"
}, 1000);
$( ".card" ).animate({
left: 0
}, 1000, function() {
$(".status").text("Inactive")
});
}
This Pen doesn't use any external CSS resources.