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>
Related
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>
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);
}
}
I am working on creating a Facebook content placeholder with the shimmer effect. I just want to animate the background property (or applying the linear gradient from top left to bottom right,) from the top left and end to the bottom right.
.Box {
height: 100px;
width: 100px;
margin: 16px;
background: #f6f7f8;
border-radius: 50%;
}
.Shine {
display: inline-block;
background: linear-gradient(to right, #eeeeee 8%, #dddddd 18%, #eeeeee 33%);
background-repeat: no-repeat;
animation-duration: 1s;
animation-fill-mode: forwards;
animation-iteration-count: infinite;
animation-name: placeholderShimmer;
animation-timing-function: linear;
}
#keyframes placeholderShimmer {
0% {
background-position: -1000px 0;
}
100% {
background-position: 10px 0;
}
}
<div class="Shine">
<div class="Box"> </div>
</div>
Now it's growing linearly from left to right.
Youn need to adjust the gradient then consider percentage value to have a better effect:
.Box {
height: 100px;
width: 100px;
margin: 16px;
background: #f6f7f8;
border-radius: 50%;
}
.Shine {
display: inline-block;
background:
linear-gradient(to bottom right, #eeeeee 40%, #dddddd 50%, #eeeeee 60%);
background-size:200% 200%;
background-repeat: no-repeat;
animation:placeholderShimmer 2s infinite linear;
}
#keyframes placeholderShimmer {
0% {
background-position:100% 100%; /*OR bottom right*/
}
100% {
background-position:0 0; /*OR top left*/
}
}
<div class="Shine">
<div class="Box"></div>
</div>
The trick is that the background will be twice as big as the container (200%x200%) with a diagonal direction and we make the coloration in the middle (around 50%). Then we simply slide this big background from top left to bottom right.
Related question for more details: Using percentage values with background-position on a linear-gradient
This question already has answers here:
Background-position not working with CSS animation and linear gradient
(2 answers)
Use CSS3 transitions with gradient backgrounds
(19 answers)
Closed 4 years ago.
I want to move my background using css horizontally.
I've looked at this demo, but they're using an actual image. I want to be able to use rgba / linear-gradient instead.
This is my code:
.chat {
width: 490px;
float: left;
background: #F2F5F8;
color: #434651;
position:absolute;
overflow:hidden;
}
#keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
.chat .chat-header {
/* padding: 20px; */
border-bottom: 2px solid white;
background-image: linear-gradient(135deg, #FF5572, #FF7555);
width:1000px; /*make bigger in order to move */
overflow:hidden;
background-position: 0px 0px;
background-repeat: repeat-x;
animation: animatedBackground 4s linear infinite;
}
<div class="chat">
<div class="chat-header clearfix">
<div class="chat-about">
hi
</div>
</div>
</div>
I want it to animate in the same way as in the demo. How would i achieve that?
You can use background position to translate it through the image background like the example..
.chat {
width: 490px;
float: left;
background: #F2F5F8;
color: #434651;
position:absolute;
overflow:hidden;
}
#keyframes animatedBackground {
0% {
background-position: 0% 0%
}
50% {
background-position: 0% 100%
}
100% {
background-position: 0% 0%
}
}
.chat .chat-header {
/* padding: 20px; */
border-bottom: 2px solid white;
background-image: linear-gradient(180deg, #FF5572, blue, #FF5572);
width:1000px; /*make bigger in order to move */
overflow:hidden;
background-position: 0px 0px;
background-repeat: repeat-x;
animation: animatedBackground 4s linear infinite;
margin:0;
height:400px;
background-size: 100% 400%;
}
<div class="chat">
<div class="chat-header clearfix">
<div class="chat-about">
hi
</div>
</div>
</div>
.chat {
background: linear-gradient(134deg, #ff5572, #ff7555);
background-size: 400% 400%;
animation: Move 4s ease infinite;
}
#keyframes Move {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
There's a great tool for playing around with gradient animations at https://www.gradient-animator.com/
I am trying to fade an image diagonally. I know there are dozens of questions regarding fading images and I've gone through a lot of them but they all are either about fading left-to-right, top-to-bottom, or moving while fading.
I'm trying to make it so that an image will have a fade effect from one corner to another. The best I could come up with was rotating a white block and increasing the width of it in place.
$(document).ready(function() {
setInterval(function(){
$('.white-fade').toggleClass('white-fade-reveal');
$('.block').toggleClass('block-hide');
}, 2000);
});
.wrapper {
position: relative;
}
.block {
width: 100px;
height: 100px;
opacity: 1;
transition-delay: 1s;
transition: opacity 0.75s ease-in-out;
}
.white-fade {
position: absolute;
top: -25px;
left: -20px;
transform: rotate(45deg);
transform-origin: 75px 75px;
transition: width 1s ease-in-out;
width: 0%;
height: 150px;
background: -moz-linear-gradient(left, rgba(255,255,255,1) 0%, rgba(255,255,255,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
.block-hide {
opacity: 0;
}
.white-fade-reveal {
width: 150px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<img class="block" src="http://images.clipartpanda.com/smiley-face-transparent-background-awesome-smiley-background-2549-hd-wallpapers.png" alt="smiley"/>
<div class="white-fade"></div>
</div>
I was wondering if there was a cleaner approach to achieving this effect? It seems inevitable that some JavaScript is necessary. I added a gradient to make it cleaner but I'm not sure if there's a way to do it with CSS3 animations?
You could use a rotated Pseudo element for this.
So, in effect you would have:
+---+
| | <-- pseudo element (rotated 45 deg)
+---+
+---+
| | <-- image element
+---+
And the on hover, bring the pseudo element over the top of the image, giving the effect of the 'fade' by transitioning the opacity of the pseudo as well:
div {
height: 300px;
width: 300px;
background: url(http://placekitten.com/g/300/300);
position: relative;
transition: all 0.8s;
overflow:hidden;
}
div:before {
content: "";
position: absolute;
height: 150%;
width: 150%;
top: -150%;
left: -150%;
transition: all 2.3s;
background: white;
opacity: 0;
transform: rotate(45deg);
}
div:hover:before {
top: -25%;
left: -25%;
opacity: 1;
}
<div></div>
One thing I'd suggest is set height and width property on wrapper so you don't increase height,
I also animated width just on one selector with linear-gradient so it's slimmer, and the result looks good!!!
$(document).ready(function() {
setInterval(function(){
$( ".white-fade" ).animate({
width: "toggle",
}, 2000);
});
});
.wrapper {
position: relative;
width:100px;
height:100px;
overflow:hidden;
}
.block {
width: 100px;
height: 100px;
opacity: 1;
transition: opacity 0.5s ease-in-out;
}
.white-fade {
position: absolute;
top: 0;
left: 0;
top: -25px;
left: -20px;
transform: rotate(45deg);
transform-origin: 75px 75px;
width: 300px;
height: 150px;
background: white;
background: linear-gradient(to right, rgba(255,255,255,1) 0%,rgba(255,255,255,1) 66%,rgba(255,255,255,0) 100%); /* W3C */
opacity:1;
}
/*.block-hide {
opacity: 0;
}
.white-fade-reveal {
width: 100%;
}*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<img class="block" src="http://images.clipartpanda.com/smiley-face-transparent-background-awesome-smiley-background-2549-hd-wallpapers.png" alt="smiley"/>
<div class="white-fade"></div>
</div>