<div class="container">
<button class="button">
<i class="icon-send material-icons">send</i>
<i class="icon-check material-icons">check</i>
<span class="button-text">Send Msg</span>
</button>
</div>
* {
box-sizing: border-box;
}
html {
font-size: 62.5%;
}
body {
font-family: Roboto;
}
.container {
padding-top: 80px;
display: flex;
justify-content: center;
align-items: center;
}
.button {
background-color: #4E3CC8;
padding: 16px 32px;
border-radius: 32px;
color: #fff;
font-size: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
width: 170px;
outline: none;
border: none;
box-shadow: 0px 2px 6px #4E3CC8;
position: relative;
&-text {
transition: transform 200ms ease;
&.loading:after {
overflow: hidden;
display: inline-block;
vertical-align: bottom;
-webkit-animation: ellipsis steps(4,end) 900ms infinite;
animation: ellipsis steps(4,end) 900ms infinite;
content: "\2026"; /* ascii code for the ellipsis character */
width: 0px;
}
}
i {
font-size: 1.8rem;
}
.icon-send {
margin-right: 10px;
transition: 400ms ease;
}
.icon-check {
margin-right: 10px;
opacity: 0;
position: absolute;
left: 60px;
transform: translateY(-80px);
transition: 200ms ease;
}
}
.notransition {
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none;
}
@keyframes ellipsis {
to {
width: 20px;
}
}
@-webkit-keyframes ellipsis {
to {
width: 20px;
}
}
.material-icons {
font-family: 'Material Icons';
font-weight: normal;
font-style: normal;
font-size: 24px; /* Preferred icon size */
display: inline-block;
line-height: 1;
text-transform: none;
letter-spacing: normal;
word-wrap: normal;
white-space: nowrap;
direction: ltr;
/* Support for all WebKit browsers. */
-webkit-font-smoothing: antialiased;
/* Support for Safari and Chrome. */
text-rendering: optimizeLegibility;
/* Support for Firefox. */
-moz-osx-font-smoothing: grayscale;
/* Support for IE. */
font-feature-settings: 'liga';
}
View Compiled
const sendButton = document.querySelector('.button');
sendButton.addEventListener('click', handleClick);
function handleClick() {
const buttonText = this.querySelector('.button-text');
const sendIcon = this.querySelector('.icon-send');
sendIcon.style.transform = `scale(0.5) translateX(-200px)`;
buttonText.textContent = 'Sending';
buttonText.classList.add('loading');
buttonText.style.transform = `translateX(-10px)`;
//fake loading state
setTimeout(() => {
buttonText.style.transform = `translateY(80px)`;
buttonText.classList.remove('loading');
sendIcon.style.transition = `1000ms ease 230ms`;
sendIcon.style.transform = `scale(2) translateX(120px)`;
sendIcon.addEventListener("webkitTransitionEnd", showSentText);
}, 2000);
}
function showSentText() {
const buttonText = document.querySelector('.button-text');
const iconCheck = document.querySelector('.icon-check');
iconCheck.style.opacity = `1`;
buttonText.classList.add('notransition');
buttonText.style.transform = `translateY(-80px)`;
buttonText.textContent = 'Sent';
buttonText.offsetHeight;
buttonText.classList.remove('notransition');
iconCheck.style.transform = `translateY(0px)`;
buttonText.style.transform = `translateY(0px)`;
sendButton.removeEventListener('click', handleClick);
}
This Pen doesn't use any external JavaScript resources.