JSFiddle - React, Tailwind, and code Playground
HTML
<div class="scroll-indicator">
scroll down
<div class="scroll-arrow-container">
<div class="scroll-arrow"></div>
</div>
</div>
SCSS
.scroll-indicator {
position: absolute;
bottom: 10%;
right: 5%;
z-index: 10;
color: black;
text-align: center;
line-height: 1;
transition: opacity 0.5s ease-in-out;
}
.scrolled .scroll-indicator {
opacity: 0;
}
.scroll-arrow-container {
position: relative;
overflow: hidden;
height: 23px;
}
.scroll-arrow {
width: 100%;
height: 100%;
animation: slideOutIn 4s ease-in-out infinite;
}
$bigPercent: 15;
$percentLeft: 100 - $bigPercent;
@keyframes slideOutIn {
0%, #{$percentLeft / 2}%, #{$percentLeft}%, 100% {
transform: translateY(0);
}
#{$percentLeft / 3}%, #{$percentLeft * 2 / 3}% {
transform: translateY(15%);
}
#{100 - $bigPercent / 2}% {
transform: translateY(100%);
}
#{100 - $bigPercent / 2 + 0.0001}% {
transform: translateY(-100%);
}
}
.scroll-arrow::before,
.scroll-arrow::after {
content: '';
position: absolute;
left: 30%;
top: 35%;
width: 19%;
height: 18%;
background-color: black;
transform: skewY(25deg);
}
.scroll-arrow::after {
transform: translateX(92%) skewY(-25deg);
}
JavaScript
function animateThings(currTime) {
if(window.pageYOffset != 0) {
document.body.classList.add("scrolled");
} else {
document.body.classList.remove("scrolled");
}
}
window.requestAnimationFrame(animateThings);