CSS loader position
Is it possible to limit the vertical position from the top of tall elements?
HTML
<!-- loaders on short elements look great - all centred -->
<section>
<div data-loader-overlay>
<span data-loader></span>
</div>
</section>
<!-- this is a loader placed on a very tall element -->
<!-- the dots might be off-screen -->
<!-- ideal: "no more than X pixels from the top" -->
<section style="height: 1000px;">
<div data-loader-overlay>
<span data-loader></span>
</div>
</section>
SCSS
$loader-size: 0.5;
$loader-speed: 0.4s;
$loader-color: #008080;
$loader-radius: 100%;
[data-loader-overlay] {
width: 100%;
height: 100%;
@include absolute(0, 0, 0, 0);
z-index: 3;
display: flex;
justify-content: center;
align-items: center;
background: rgba(255,255,255,0.5);
body > & {
position: absolute;
background: #333;
}
}
[data-loader] {
display: inline-block;
border-radius: $loader-radius;
margin-left: 0;
width: 1em;
height: 1em;
transition-duration: $loader-speed;
background-color: $loader-color;
font-size: 1rem * $loader-size;
position: relative;
animation: loader ($loader-speed * 3) infinite;
&:after,
&:before {
content: '';
display: inline-block;
border-radius: $loader-radius;
margin-left: 0;
width: 1em;
height: 1em;
animation: loader ($loader-speed * 3) infinite;
transition-duration: $loader-speed;
position: absolute;
left: 150%;
animation-delay: $loader-speed;
background-color: $loader-color;
}
&:after {
left: -150%;
animation-delay: $loader-speed * 2;
}
}
@keyframes loader {
0% {
background-color: $loader-color;
}
50% {
background-color: lighten($loader-color, 5%);
}
100% {
background-color: lighten($loader-color, 10%);
}
}
section {
width: 45%;
display: inline-block;
vertical-align: top;
height: 50px;
position: relative;
outline: 1px solid #ccc;
}