<div id="wrap-animate">
<div class="animate-box" id="blur-box">
<h3>Blur Transition</h3>
<a id='trigger'>GO!</a>
<div class="box"></div>
</div>
</div>
@import url(https://fonts.googleapis.com/css?family=Oswald:400,300);
* {
box-sizing: border-box;
}
body {
background-color: #e6e6e6;
font-family: "Oswald", sans-serif;
}
#wrap-animate {
display: border-box;
width: 600px;
margin: 0px auto;
}
.animate-box {
position: relative;
width: 100%;
margin-bottom: 80px;
}
.animate-box h3 {
margin-bottom: 20px;
font-size: 1.6em;
}
.animate-box h3 small {
font-weight: 300;
font-style: italic;
}
.animate-box a {
margin-bottom: 20px;
background: #55f;
color: #fff;
border-radius: 5px;
padding: 8px;
font-weight: 300;
display: inline-block;
cursor: pointer;
}
.box {
background-color: #f08;
width: 50px;
height: 50px;
position: absolute;
border-radius: 10px;
}
.box.animateIn {
animation: ninja ease-in-out 0.2s;
animation-fill-mode: forwards;
}
.box.animateOut {
animation: ninjaOut ease-in-out 0.2s;
animation-fill-mode: forwards;
}
@keyframes ninja {
0% {
left: 0;
transform: scale(1) translate3d(0, 0, 0);
}
50% {
filter: blur(3px);
}
100% {
filter: blur(0);
left: 100%;
transform: scale(1) translate3d(0, 0, 0);
}
}
@keyframes ninjaOut {
0% {
filter: blur(0);
left: 100%;
transform: scale(1) translate3d(0, 0, 0);
}
50% {
filter: blur(3px);
}
100% {
left: 0;
transform: scale(1) translate3d(0, 0, 0);
}
}
const trigger = document.querySelector("#trigger");
const box = document.querySelector(".box");
trigger.addEventListener("click", (e) => {
const classArray = Object.keys(box.classList).map((x) => box.classList[x]);
if (classArray.includes("animateIn")) {
box.classList.remove("animateIn");
box.classList.add("animateOut");
} else {
box.classList.add("animateIn");
box.classList.remove("animateOut");
}
});
This Pen doesn't use any external CSS resources.