I'm trying to animate a loading icon using an image. What I'm trying to achieve is to have the image animate between two colours from left to right infinitely. This is done in Angular 7. I'm new to animations but as far as I understand I can solve this with CSS animations.
What I want is something similar to the example below. Only I want the grayscale to disappear to the right, and instead of a grayscale I want to pick two different colours.
All help is appreciated!
body {
margin: 0;
}
.effect {
position: relative;
}
.effect-dup {
filter: grayscale(100%);
position: absolute;
overflow: hidden;
top: 0;
left: 0;
width: 0;
animation: width 1s ease-in-out;
animation-fill-mode: forwards;
}
@keyframes width {
from {
width: 0;
}
to {
width: 100%;
}
}
<div class="effect">
<img src="https://placeimg.com/640/480/nature" />
<div class='effect-dup'><img src="https://placeimg.com/640/480/nature" /></div>
</div>
<div class="effect">
<img src="https://placeimg.com/640/480/tech" />
<div class='effect-dup'>
<img src="https://placeimg.com/640/480/tech" />
</div>
</div>
You can consider an extra layer and mix-blend-mode. Simply adjust the coloration and the blending to obtain the color you want. You will no more need to duplicate the image.
body {
margin: 0;
}
img {
width: 200px;
display: block;
}
.effect {
position: relative;
display: inline-block;
overflow:hidden;
}
.effect:before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
animation: width 2s ease-in-out infinite;
mix-blend-mode: color;
background: linear-gradient(blue,red);
}
@keyframes width {
from {
transform:translateX(-100%);
}
to {
transform:translateX(100%);
}
}
<div class="effect">
<img src="https://placeimg.com/640/480/nature" />
</div>
<div class="effect">
<img src="https://placeimg.com/640/480/tech" />
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With