Loop gradient effect on existing button - css

I have a button that is already exist :
<div class="button-loader locationButton brandBlue fontMediumTitle " id="locationButton"></div>
I would like to be able to add a class button-loader , to this button or any other button, and
keep it's current background color
animate from left to right and back, in a loop - so that I start with the original color and change its opacity from left to right and back to original.(say it become 0.5 in opacity from left, and back to 1.0 from right)
.button-loader {
width: 100%;
height: 100%;
display: block;
background: linear-gradient(to right, rgba(245, 245, 245, 0.95), rgba(255, 255, 255, 0.0));
background-size: 200% 100%;
background-position: right bottom;
transition: all 1.5s ease-out;
}
.button-loader:hover {
background-position: left bottom;
}
Current code will not loop forever and will not keep the original color before animation begin(its already gradient)

Consider the gradient on a pseudo element instead where you can easily keep the initial background color:
.button-loader {
width: 100px;
height: 100px;
border:1px solid;
background-size: 200% 100%;
transition: all 1.5s ease-out;
position:relative;
z-index:0;
}
.button-loader:before {
content:"";
position:absolute;
z-index:-1;
top:0;
right:0;
left:0;
bottom:0;
background: linear-gradient(to right,rgba(255, 255, 255, 0.0), rgba(245, 245, 245, 0.95) 40% 60%, rgba(255, 255, 255, 0.0));
background-size:600% 100%;
background-position:right;
transition:1s all;
}
.button-loader:hover:before {
background-position:left;
}
<div class="button-loader" style="background:blue;"></div>
<div class="button-loader" style="background:red;"></div>
<div class="button-loader" style="background:linear-gradient(red,purple);"></div>
For an infinite animation, you can replace transition with animation:
.button-loader {
width: 100px;
height: 100px;
border:1px solid;
background-size: 200% 100%;
transition: all 1.5s ease-out;
position:relative;
z-index:0;
}
.button-loader:before {
content:"";
position:absolute;
z-index:-1;
top:0;
right:0;
left:0;
bottom:0;
background: linear-gradient(to right,rgba(255, 255, 255, 0.0), rgba(245, 245, 245, 0.95) 45% 55%, rgba(255, 255, 255, 0.0));
background-size:600% 100%;
background-position:right;
animation:change 1s infinite linear;
}
#keyframes change {
to {
background-position:left;
}
}
<div class="button-loader" style="background:blue;"></div>
<div class="button-loader" style="background:red;"></div>
<div class="button-loader" style="background:linear-gradient(red,purple);"></div>
You can also animate translate for better performance:
.button-loader {
width: 100px;
height: 100px;
border:1px solid;
background-size: 200% 100%;
transition: all 1.5s ease-out;
position:relative;
z-index:0;
overflow:hidden;
}
.button-loader:before {
content:"";
position:absolute;
z-index:-1;
top:0;
right:0;
width:600%;
bottom:0;
background: linear-gradient(to right,rgba(255, 255, 255, 0.0), rgba(245, 245, 245, 0.95) 45% 55%, rgba(255, 255, 255, 0.0));
animation:change 1s infinite linear;
}
#keyframes change {
to {
transform:translate(84%);
}
}
<div class="button-loader" style="background:blue;"></div>
<div class="button-loader" style="background:red;"></div>
<div class="button-loader" style="background:linear-gradient(red,purple);"></div>

Related

Transition of background image on hover not working [duplicate]

This question already has answers here:
CSS3 background image transition
(13 answers)
Closed 4 months ago.
When I put my mouse over it, the background image shows up in an instant. I want to show a gradual trasition. How can I fix this?
.category__mid {
min-height: 260px;
width: 200px;
border: 2px solid #000;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-color: rgba(255, 255, 255, 1);
background-blend-mode: lighten;
transition: all 0.9s ease;
}
.category__mid:hover {
background-color: rgba(255, 255, 255, 0);
background-blend-mode: normal;
}
<div class="category__mid" style="background-image: url('https://i.postimg.cc/NG159gHv/pexels-kampus-production-8439682.jpg')">
<h3>I want to show transition on hover. NOT when the user leaves</h3>
</div>
change the css as
.category__mid {
min-height: 260px;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-color: rgba(255,255,255,1);
background-blend-mode: lighten;
}
.category__mid:hover {
background-color: rgba(255,255,255,0);
transition: all 0.9s ease ;
}
Change the css to;
.category__mid {
min-height: 260px;
width: 200px;
border: 2px solid #000;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-color: rgba(255,255,255,1);
background-blend-mode: lighten;
transition: all 0.9s ease;
}
.category__mid:hover {
animation: fade-in 0.9s ease;
background-color: rgba(255,255,255,0);
}
#keyframes fade-in {
0% {
background-blend-mode: lighten;
}
100% {
background-blend-mode: normal;
}
}
Unfortunately you can't transition the background image of a div.
but you can use an animation.

CSS Background: Linear Gradient - Animation is not functioning as Wished to be

I am facing an issue implementing the animation. The below code snippet is working fine. Currently, the background is animating from left to right only. But I want to reverse the above animation when its cycle ends (reaches the bottom right corner), then the animation should start from there to the left.
I also tried adding a new animation with a 1.5s delay (when the first
animation ends) by changing the background position (with javascript),
but it didn't work.
I've already read all the possible answers but didn't find a useful one. Can anyone assist with a suggestion/alternative approach or point out what I'm doing wrong? Any help would be greatly appreciated..! 🤗
.user-img {
width: 100px;
height: 100px;
border-radius: 50%;
animation: bg-slide 1.5s ease infinite;
border: 6px solid rgba(255, 255, 255, 0.12);
background: 0 0/300% 300% linear-gradient(-60deg, #eee 40%, #18d26e 50%, #eee 60%);
}
#keyframes bg-slide {
from {
background-position: 100% 50%;
}
to {
background-position: 0 50%;
}
}
<img src="https://images.unsplash.com/photo-1630208232589-e42b29428b19?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8cHJvZmlsZSUyMHBob3RvfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=400&q=60" alt="user-image" class="user-img" />
You have to add alternate to your animation setting (for the animation-direction):
.user-img {
width: 100px;
height: 100px;
border-radius: 50%;
animation: bg-slide 1.5s ease infinite alternate;
border: 6px solid rgba(255, 255, 255, 0.12);
background: 0 0/300% 300% linear-gradient(-60deg, #eee 40%, #18d26e 50%, #eee 60%);
}
#keyframes bg-slide {
from {
background-position: 100% 50%;
}
to {
background-position: 0 50%;
}
}
<img src="https://images.unsplash.com/photo-1630208232589-e42b29428b19?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8cHJvZmlsZSUyMHBob3RvfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=400&q=60" alt="user-image" class="user-img" />
Add animation-direction: alternate; in the .user-img class.
.user-img {
width: 100px;
height: 100px;
border-radius: 50%;
animation: bg-slide 1.5s ease infinite;
animation-direction: alternate;
border: 6px solid rgba(255, 255, 255, 0.12);
background: 0 0/300% 300% linear-gradient(-60deg, #eee 40%, #18d26e 50%, #eee 60%);
}
#keyframes bg-slide {
from {
background-position: 100% 50%;
}
to {
background-position: 0 50%;
}
}
<img src="https://images.unsplash.com/photo-1630208232589-e42b29428b19?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8OXx8cHJvZmlsZSUyMHBob3RvfGVufDB8fDB8fA%3D%3D&auto=format&fit=crop&w=400&q=60" alt="user-image" class="user-img" />

Animated dots with css, making them move forever

I can't seem to make this animation move forever without adding more dots in span.
I would like the amount of dots not to be dependent on the "loading-dots" class, as it is adding more dots increases the duration but its a pain. Could it be possible to have a single dot but animate it forever. I like the ability to change the speed and direction.
Here's the CodePen
* {
box-sizing: border-box;
}
body {
padding: 50px;
background: white;
}
.container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 20px 20px 0px 20px;
}
.loading-container {
overflow: hidden;
float: left;
width: 200px;
}
.loading-dots {
display: inline-block;
animation-name: loading-dots;
animation-duration: 5s;
animation-timing-function: linear;
font-size: 50px;
position: relative;
top: -27px;
color: rgba(blue, 1);
font-family: sans-serif;
white-space: no-wrap;
}
.loading-title {
overflow: display;
position: relative;
font-size: 30px;
top: 10px;
margin-right: 10px;
font-family: monospace;
color: rgba(white, 1);
float: left;
}
#keyframes loading-dots {
0% {
transform: translateX(-600px);
}
100% {
transform: translateX(0px);
}
}
<div class="container">
<span class="loading-title"></span>
<div class="loading-container">
<span class="loading-dots">.................
</span>
</div>
</div>
You can do this with a simple background where it will be easy to control the animation and also the dimension of your dots:
.dots {
height:5px; /*to control the overall height*/
width:200px; /*to control the overall width*/
margin:50px;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px, /*5px of transparent*/
blue 5px,blue 10px); /*then 5px of blue */
background-size:200% 100%;
animation:change 3s linear infinite;
}
#keyframes change{
to {
background-position:right;
}
}
<div class="dots"></div>
To change the direction you simply change the position:
.dots {
height:5px;
width:200px;
margin:50px;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
background-size:200% 100%;
background-position:right;
animation:change 3s linear infinite;
}
#keyframes change{
to {
background-position:left;
}
}
<div class="dots"></div>
You can check this for more details about the different values used: Using percentage values with background-position on a linear gradient
Another idea using animation on transform :
.dots {
height:5px;
width:200px;
margin:50px;
position:relative;
overflow:hidden;
}
.dots::before {
content:"";
position:absolute;
top:0;
left:0;
right:-100%;
bottom:0;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
animation:change 3s linear infinite;
}
#keyframes change{
to {
transform:translateX(-50%);
}
}
<div class="dots"></div>
Changing the direction:
.dots {
height:5px;
width:200px;
margin:50px;
position:relative;
overflow:hidden;
}
.dots::before {
content:"";
position:absolute;
top:0;
left:-100%;
right:0;
bottom:0;
background-image:
repeating-linear-gradient(to right,
transparent,transparent 5px,
blue 5px,blue 10px);
animation:change 3s linear infinite;
}
#keyframes change{
to {
transform:translateX(50%);
}
}
<div class="dots"></div>
Reduce the negative pixel margin. -600px is pretty excessive for 16 dots.
#keyframes loading-dots {
0% {
transform: translateX(-50px);
}
100% {
transform: translateX(0px);
}
}

Two CSS animation interfere with each other

I've created this snippet on Codepen: the earth rotates and the car moves. However, when car moves it makes the earth rotate too. I want all elements to go their own path.
Why does the car affect the earth, and how can that be avoided?
body {
background: url(https://news.vanderbilt.edu/files/NASA_SMBH1.jpg);
background-size: 1000px;
}
#firstimg {
background-image: url(http://www.21tech.ir/dfxhfgh.gif);
position: absolute;
background-repeat: no-repeat;
background-size: 100px;
animation: anim1 14s infinite linear;
margin: 40px;
}
#earth {
margin-left: 100px;
width: 500px;
height: 500px;
background: url(http://www.drodd.com/images14/map-of-earth1.jpg);
border-radius: 50%;
background-size: 1000px;
box-shadow: inset 16px 0 40px 6px rgb(0, 0, 0), inset -3px 0 6px 2px rgba(255, 255, 255, 0.2);
animation-name: rotate;
animation-duration: 30s;
animation-iteration-count: infinite;
animation-timing-function: linear;
filter: brightness(50%);
}
#keyframes rotate {
from {
background-position-x: 0px;
}
to {
background-position-x: 1000px;
}
}
#keyframes anim1 {
0%,
100% {
transform: translate(0, 0) rotate(0deg)
}
50% {
transform: translate(20px, 20px) rotate(10deg)
}
}
<div id="firstimg">
<div>
<div id="earth"></div>
You have not closed you firstimg div tag, hence it runs under a single div
<div id="firstimg"></div>
<div id="earth"></div>
Follow Codepen

animate radial-gradient CSS3 : move from left to right? [duplicate]

This question already has answers here:
How to animate a radial-gradient using CSS?
(3 answers)
Closed 2 years ago.
I want animate a background with a radial-gradient radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%), to move it from left to right
http://jsfiddle.net/odsb1fjh/2/
how can I do to animate this radial-gradient to move infinite on div from left to right?
I have already try animation and keyframe background-position: left/right bottom; but don't works.
Try this
div
{
position:absolute;
width: 250px;
height: 250px;
background-color: black;
background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png)
}
div:after
{
content:'';
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background-image: -webkit-radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%);
background-position: -1500px 0;
background-repeat: no-repeat;
-webkit-animation: animation 3s ease-in-out infinite;
}
#-webkit-keyframes animation {
from {background-position: -250px 0;}
to {background-position: 250px 0;}
}
<div></div>
or this
div
{
position:absolute;
width: 250px;
height: 250px;
background-color: black;
background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png);
overflow:hidden
}
div:after
{
content:'';
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background-image: -webkit-radial-gradient(circle, rgba(255,255,255,0.8) 0, rgba(255,255,255,0) 100%);
-webkit-animation: animation 3s ease-in-out infinite;
}
#-webkit-keyframes animation {
from {left: -250px;}/**you can use translate3d(-250px,0,0)*/
to {left: 250px;}/** translate3d(250px,0,0)*/
}
<div></div>
"but we can see the border of "square" where is the light radial" - Why use radial background at all, simply use:
div
div {
position: absolute;
width: 250px;
height: 250px;
background-color: black;
background-image: url(http://frontend.lostboys.nl/presenations/Icons-fonts/img/chrome.png);
overflow: hidden;
}
div:after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgb(255, 255, 255);
background: linear-gradient(
90deg,
rgba(250, 250, 250, 0) 0%,
rgba(250, 250, 250, 0.5) 60%,
rgba(250, 250, 250, 0) 100%
);
-webkit-animation: animation 3s ease-in-out infinite;
}
#-webkit-keyframes animation {
from {
left: -250px;
}
to {
left: 250px;
}
}
<div></div>

Resources