Skip to content

Instantly share code, notes, and snippets.

@laughingclouds
Last active August 25, 2021 13:21
Show Gist options
  • Save laughingclouds/e00cbc62a3febc1cc7f9cae2fea16738 to your computer and use it in GitHub Desktop.
Save laughingclouds/e00cbc62a3febc1cc7f9cae2fea16738 to your computer and use it in GitHub Desktop.
HTML code and CSS rules for a wave like animation, more animation sources given in the comments
<!-- code taken from: https://blog.hubspot.com/website/css-loading-animation -->
<!-- code pen link: https://codepen.io/Bilal1909/pen/pobgJae -->
<!-- The style rules and the div element code should be kept together.
They've been kept seperately for just cleanliness -->
<div class="center">
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
<div class="wave"></div>
</div>
.center {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #000;
}
.center:hover>* {
background: red;
}
.wave {
width: 5px;
height: 100px;
background: linear-gradient(45deg, cyan, #fff);
margin: 10px;
animation: wave 1s linear infinite;
border-radius: 20px;
}
.wave:nth-child(2) {
animation-delay: 0.1s;
}
.wave:nth-child(3) {
animation-delay: 0.2s;
}
.wave:nth-child(4) {
animation-delay: 0.3s;
}
.wave:nth-child(5) {
animation-delay: 0.4s;
}
.wave:nth-child(6) {
animation-delay: 0.5s;
}
.wave:nth-child(7) {
animation-delay: 0.6s;
}
.wave:nth-child(8) {
animation-delay: 0.7s;
}
.wave:nth-child(9) {
animation-delay: 0.8s;
}
.wave:nth-child(10) {
animation-delay: 0.9s;
}
@keyframes wave {
0% {
transform: scale(0);
}
50% {
transform: scale(1);
}
100% {
transform: scale(0);
}
}
// An scss version of style.css, because why not?
@use "sass:math";
.center {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #000;
&:hover>* {
background: red;
}
}
.wave {
width: 5px;
height: 100px;
background: linear-gradient(45deg, cyan, #fff);
margin: 10px;
animation: wave 1s linear infinite;
border-radius: 20px;
@for $i from 2 to 10 {
&:nth-child(#{$i}) {
animation-delay: #{math.div($i - 1, 10)}s;
}
}
}
@keyframes wave {
0% {
transform: scale(0);
}
50% {
transform: scale(1);
}
100% {
transform: scale(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment