Skip to content

Instantly share code, notes, and snippets.

@claudioacioli
Created November 5, 2020 02:40
Show Gist options
  • Save claudioacioli/3896d88776f1ab5404bd018e13ab091b to your computer and use it in GitHub Desktop.
Save claudioacioli/3896d88776f1ab5404bd018e13ab091b to your computer and use it in GitHub Desktop.
Pure CSS Submitting button
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.button {
border-radius: 4px;
text-align: center;
padding: 1em;
transition: all 0.5s;
cursor: pointer;
width: 7em;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
width:1em;
height:1em;
border:2px solid transparent;
border-top-color:black;
border-radius: 50%;
animation: spin 2s linear infinite;
}
.submitting, .submitting > span {
cursor: not-allowed;
}
.submitting span{
padding-right: 25px;
}
.submitting span:after{
opacity: 1;
right: 0;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<h2>Animated Button</h2>
<button class="button"><span>Salvar </span></button>
<script>
document.querySelector("button").addEventListener("click", function(e) {
const element = e.target;
element.classList.add("submitting");
element.disabled = true;
setTimeout(() => {
element.classList.remove("submitting");
element.disabled = false;
},5000);
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment