Reset CSS Animations
by James Connolly
HTML
<div class="copy-success">
<span class="h1">Copied to Clipboard</span>
</div>
<div class="button copy-to-clipboard">
Click me
</div>
CSS
body{
width: 100%;
height: 100%;
position: relative;
font-family: arial;
font-size: 20px;
}
.copy-success{
display: table;
margin: 0;
padding: 25px;
width: 100%;
height: 100%;
text-align: center;
background: #91e35fe6;
color: #fff;
opacity: 0;
pointer-events: none;
position: fixed;
right: 0;
top: 0;
}
.copy-success span{
display: table-cell;
opacity: 0;
vertical-align: middle;
}
.copy-animation {
-webkit-animation: success 2s ease;
-moz-animation: success 2s ease;
-webkit-animation-iteration-count: 1;
-moz-animation-iteration-count: 1;
}
.copy-animation-text {
-webkit-animation: success-text 1.8s ease;
-moz-animation: success-text 1.8s ease;
-webkit-animation-iteration-count: 1;
-moz-animation-iteration-count: 1;
-webkit-animation-delay: 0.1s;
-moz-animation-delay: 0.1s;
}
@-webkit-keyframes success {
0% { opacity: 0; pointer-events: none;}
15% { opacity: 1; pointer-events: none;}
85% { opacity: 1; pointer-events: none;}
100% { opacity: 0; pointer-events: none;}
}
@-moz-keyframes success {
0% { opacity: 0; pointer-events: none;}
15% { opacity: 1; pointer-events: none;}
85% { opacity: 1; pointer-events: none;}
100% { opacity: 0; pointer-events: none;}
}
@-webkit-keyframes success-text {
0% { transform: translateY(25px); }
15% { transform: translateY(0); }
85% { transform: translateY(0); }
100% { transform: translateY(-25px); }
}
@-moz-keyframes success-text {
0% { opacity: 0; transform: translateY(25px); }
15% { opacity: 1; transform: translateY(0); }
85% { opacity: 1; transform: translateY(0); }
100% { opacity: 0; transform: translateY(-25px); }
}
.button {
background-color: #ccc;
border-radius: 10px;
padding: 10px;
margin: 10px;
cursor: pointer;
display: inline-block;
font-family: sans-serif;
}
.button:hover {
background-color: #eee;
}
JavaScript
$('.copy-to-clipboard').click(function(){
$target1 = $('.copy-success');
$target1.removeClass('copy-animation');
setTimeout(function() {
$target1.addClass('copy-animation');
}, 100);
$target2 = $('.copy-success span');
$target2.removeClass('copy-animation-text');
setTimeout(function() {
$target2.addClass('copy-animation');
}, 100);
});