Replay CSS animation with VueJS
by Icesofty
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.9.6/tailwind.min.css">
<div
id="app"
class="bg-purple-500 flex justify-center items-center flex-col h-screen w-screen"
>
<div class="success-checkmark" :key='replay'>
<div class="check-icon">
<span class="icon-line line-tip"></span>
<span class="icon-line line-long"></span>
<div class="icon-circle"></div>
<div class="icon-fix"></div>
</div>
</div>
<button class="px-2 py-1 bg-white rounded-sm text-purple-500" @click='replay++'>
Replay
</button>
<p class="mt-4">
Replay key : {{ replay }}
</p>
</div>
CSS
/**
* Extracted from: SweetAlert
* Modified by: Istiak Tridip
*/
.success-checkmark {
width: 80px;
height: 115px;
margin: 0 auto;
}
.success-checkmark .check-icon {
width: 80px;
height: 80px;
position: relative;
border-radius: 50%;
box-sizing: content-box;
border: 4px solid #edf2f7;
}
.success-checkmark .check-icon::before {
top: 3px;
left: -2px;
width: 30px;
transform-origin: 100% 50%;
border-radius: 100px 0 0 100px;
}
.success-checkmark .check-icon::after {
top: 0;
left: 30px;
width: 60px;
transform-origin: 0 50%;
border-radius: 0 100px 100px 0;
animation: rotate-circle 4.25s ease-in;
}
.success-checkmark .check-icon::before,
.success-checkmark .check-icon::after {
content: '';
height: 100px;
position: absolute;
background: #9f7aea;
transform: rotate(-45deg);
}
.success-checkmark .check-icon .icon-line {
height: 5px;
background-color: #edf2f7;
display: block;
border-radius: 2px;
position: absolute;
z-index: 10;
}
.success-checkmark .check-icon .icon-line.line-tip {
top: 46px;
left: 14px;
width: 25px;
transform: rotate(45deg);
animation: icon-line-tip 0.75s;
}
.success-checkmark .check-icon .icon-line.line-long {
top: 38px;
right: 8px;
width: 47px;
transform: rotate(-45deg);
animation: icon-line-long 0.75s;
}
.success-checkmark .check-icon .icon-circle {
top: -4px;
left: -4px;
z-index: 10;
width: 80px;
height: 80px;
border-radius: 50%;
position: absolute;
box-sizing: content-box;
border: 4px solid rgba(255, 255, 255, 0.5);
}
.success-checkmark .check-icon .icon-fix {
top: 8px;
width: 5px;
left: 26px;
z-index: 1;
height: 85px;
position: absolute;
transform: rotate(-45deg);
background-color: #9f7aea;
}
@keyframes rotate-circle {
0% {
transform: rotate(-45deg);
}
5% {
transform: rotate(-45deg);
}
12% {
transform: rotate(-405deg);
}
100% {
transform: rotate(-405deg);
}
}
@keyframes icon-line-tip {
0% {
width:...
Vue
new Vue({
el: "#app",
data: {
replay: 0
},
methods: {
addUser: function() {
this.helloNames.push({
name: this.newUser
});
// When the method is executed, we clear the newUser data
this.newUser = ""
}
},
filters: {
// the value is the item.name
capitalize: function(value) {
// We uppercase the first letter
return value.charAt(0).toUpperCase() + value.slice(1);
}
},
computed: {
listenUser: function() {
if (this.newUser.length > 1) {
return this.newUser + " is a great name!"
}
}
},
})