Button Animation Trigger
by James Connolly
HTML
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
<button class="button copy-to-clipboard">
<i class="fas fa-cart-plus"></i>
</button>
SCSS
.button {
font-family: 'Montserrat', Helvetica, Arial, Sans-Serif;
display: inline-block;
margin: 0;
padding: 15px;
width: 200px;
background: ;
border-radius: 5px;
color: #FFF;
font-size: 20px;
text-align: center;
text-decoration: none;
cursor: pointer;
overflow: hidden;
transition: all 0.3s ease;
position: relative;
outline: none;
}
.button:after {
content: 'copied!';
display: block;
padding: 10px 0;
width: 100%;
height: 100%;
color: white;
opacity: 0;
position: absolute;
left: 0;
top: 0;
}
.button:active {
transform: scale(0.9);
}
.button:hover,
.button:focus {
background: #004CA3;
border-color: #004CA3;
color: #fff;
}
.button.copied {
-webkit-animation: success 2s ease;
-moz-animation: success 2s ease;
-webkit-animation-iteration-count: 1;
-moz-animation-iteration-count: 1;
}
.button.copied:after {
-webkit-animation: success-text 1.5s ease;
-moz-animation: success-text 1.5s ease;
-webkit-animation-iteration-count: 1;
-moz-animation-iteration-count: 1;
-webkit-animation-delay: 0.2s;
-moz-animation-delay: 0.2s;
}
@-webkit-keyframes success {
0% {}
15% { background: #62E03C; color: #62E03C; border-color: #62E03C; }
85% { background: #62E03C; color: #62E03C; border-color: #62E03C; }
100% {}
}
@-moz-keyframes success {
0% {}
15% { background: #62E03C; color: #62E03C; border-color: #62E03C; }
85% { background: #62E03C; color: #62E03C; border-color: #62E03C; }
100% {}
}
@-webkit-keyframes success-text {
0% { opacity:0; transform: translateY(20px)}
15% { opacity:1; transform: translateY(0)}
85% { opacity:1; transform: translateY(0)}
100% { opacity:0; transform: translateY(-20px)}
}
@-moz-keyframes success-text {
0% { opacity:0; transform: translateY(20px)}
15% { opacity:1; transform: translateY(0)}
85% { opacity:1; transform: translateY(0)}
100% { opacity:0; transform: translateY(-20px)}
}
JavaScript
$('.copy-to-clipboard').click(function() {
$target1 = $('.copy-to-clipboard');
$target1.removeClass('copied');
setTimeout(function() {
$target1.addClass('copied');
}, 100);
});