Animate text fill from left to right - css

I wanted to animate a the text fill with CSS. The Text should be filled with color from left to right.
this is my CSS:
.box-with-text {
background-image: -webkit-linear-gradient(right, crimson 50%, white 50%);
background-repeat: repeat;
background-position: 0 0;
background-size: 200% 100%;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-animation: stripes normal forwards ease-in-out;
animation: stripes 2s normal forwards ease-in-out;
}
Now only the first letter is color-filled.
here is the fiddle

you may also take a look at flex (for centering things) and mix-blend-mode, so it can be avalaible also for Firefox:
.box-with-text {
text-transform: uppercase;
font: bold 26vmax/.8 Open Sans, Impact;
background: black;
display: table;
color: white;
mix-blend-mode: multiply
}
#-webkit-keyframes stripes {
to {
background-size:100% 100%;
}
}
#keyframes stripes {
to {
background-size:100% 100%;
}
}
html {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-align:center;
-webkit-align-items:center;
-ms-flex-align:center;
align-items:center;
height: 100%;
background: black;
}
body {
margin: auto;
background: -webkit-linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
background: linear-gradient( crimson , crimson) turquoise no-repeat 0 0;
background-size: 0 100%;
-webkit-animation: stripes 2s linear infinite;
animation: stripes 2s linear infinite;
}
<div class="box-with-text">
Text
</div>
http://codepen.io/gc-nomade/pen/XKNKzd

/* Main styles */
#import url(http://fonts.googleapis.com/css?family=Open+Sans:800);
.box-with-text {
background-image: -webkit-linear-gradient(left, crimson 50%, white 50%);
background-repeat: repeat;
background-position: 0 0;
background-size: 100% 200px;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
-webkit-animation: stripes 2s linear infinite;
animation: stripes 2s linear infinite;
}
#-webkit-keyframes stripes {
100% {
background-position: 0 -50px;
}
}
#keyframes stripes {
100% {
background-position: 385px 0;
}
}
/* Other stuff */
body {
overflow: hidden;
background: #000;
color: #FFF;
}
.box-with-text {
position: absolute;
top: 50%;
left: 50%;
white-space: nowrap;
text-align: center;
text-transform: uppercase;
font: bold 26vmax/.8 Open Sans, Impact;
-webkit-transform: translateX(-50%) translateY(-50%);
-ms-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}
<div class="box-with-text">
Text
</div>
In this case you should change
#keyframes stripes {
100% {
background-position: 385px 0;
}
}
position depends on text width;

Related

Creating seamless animation with CSS linear gradient

div {
border-radius: 2rem;
width: 10rem;
height: 10rem;
background-color: #0dd;
background-image:
linear-gradient(
-45deg,
rgba( 0,0,0,0.125 ), transparent, rgba( 0,0,0,0.125 ), transparent
);
}
div {
animation-name: diagonal_move;
animation-duration: 6s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#keyframes diagonal_move {
0% {
background-position: 0rem 0rem;
}
100% {
background-position: 10rem 10rem;
}
}
<html>
<head>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
As the linear gradient above animates the edges of the gradient can clearly be seen - opposed to blending seamlessly with its surroundings.
A solution attempted to hide the edges was to overlay additional gradients on top:
div {
border-radius: 2rem;
width: 10rem;
height: 10rem;
background-color: #0dd;
background-image:
linear-gradient( #0dd, transparent, transparent, transparent, #0dd ),
linear-gradient( 90deg, #0dd, transparent, transparent, transparent, #0dd ),
linear-gradient(
-45deg,
rgba( 0,0,0,0.125 ), transparent, rgba( 0,0,0,0.125 ), transparent
);
}
div {
animation-name: diagonal_move;
animation-duration: 6s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#keyframes diagonal_move {
0% {
background-position: 0rem 0rem;
}
100% {
background-position: 10rem 10rem;
}
}
<html>
<head>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
The issue with this approach is it hides much of the original gradient along with the seams. It also creates bright lines where the seams would be.
So is there any way to flip or mirror gradients when they end to create a seamless pattern? Or perhaps the original gradient could be larger and zoomed out to give the illusion of a seamless pattern. How could this be implemented?
Your gradient consists of 3 parts (between 4 reference points/color definitions), which creates a kind of "asymmetrical" structure since there's a different color at the end than at the beginning. If you add another reference point / color (same as first one), the gradient has the same color at the beginning and end and also in the other two corners of the square, and therefore the animation works smooth:
div {
border-radius: 2rem;
width: 10rem;
height: 10rem;
background-color: #0dd;
background-image:
linear-gradient(
-45deg,
rgba( 0,0,0,0.125 ), transparent, rgba( 0,0,0,0.125 ), transparent, rgba( 0,0,0,0.125 )
);
}
div {
animation-name: diagonal_move;
animation-duration: 6s;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
#keyframes diagonal_move {
0% {
background-position: 0rem 0rem;
}
100% {
background-position: 10rem 10rem;
}
}
<html>
<head>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
body {
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div></div>
</body>
</html>
In such case better consider a repeating gradient that is twice bigger than the element so you don't have to bother with specific values inside background-position:
.box {
border-radius: 2rem;
width: 10rem;
height: 10rem;
background-color:;
background:
repeating-linear-gradient(
-45deg,
rgba( 0,0,0,0.125 ), transparent, rgba( 0,0,0,0.125 ) 25%
) bottom right/200% 200%
#0dd;
animation: diagonal_move 6s linear infinite;
}
#keyframes diagonal_move {
100% {
background-position: top left;
}
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin:0;
}
<div class="box"></div>
Related for more details around the values and the calculation: Using percentage values with background-position on a linear-gradient

background images animation not working in safari react app

creating a landing page I have a map with pinpoints. theses pinpoints are just a span that through an animation I change styles. animation working just fine in fire-fox and chrome.
where I use this.changeClassName(place.style) as a variable to start animation.
The problem is safari the image properties arent working.
I noticed That
background-repeat: no-repeat; // is not working
background-size: contain // I think it isn't working
render (){
return (
<span key={`${place.name}-${place.style}`}
className={`dot ${this.changeClassName(place.style)}`}
>
</span>
}
)
// the scss
.dot {
width: 1.8rem;
height: 1.8rem;
display: flex;
border-radius: 50%;
background-color: $tangerine-yellow;
&-gt {
margin: 0.2rem 0 0 1.5rem;
&.start-animation {
-webkit-animation: dotTop 4000ms ease-out 500ms forwards;
animation: dotTop 4000ms ease-out 500ms forwards;
}
}
#keyframes dotTop {
0% {
background-image: url('../assets/icons/pin.svg');
// -webkit-background-size: contain;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
background-color: transparent;
border: none;
transform: translateY(-300px);
}
50% {
background-image: url('../assets/icons/pin.svg');
// -webkit-background-size: contain;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
width: 7rem;
height: 7rem;
background-color: transparent;
border: none;
border-radius: 50%;
transform: translateX(-50px);
top: -10rem;
}
55% { border-radius: 50%; }
57% { background-image: none; }
59% { border: none; backgroung-color: transparent }
60% { background-color: $tangerine-yellow }
70% { border-radius: 50%; }
100% {
width: 1.8rem;
height: 1.8rem;
background-image: none;
// background-color: red;
}
}

Animated Gradient in Firefox not working

I'm trying to achieve and animated gradient button that I've seen executed before and works in Firefox, but for some reason mine isn't work. I've tried prefixing the animations, but that did nothing.
.bookParty {
background: linear-gradient(to right, #e90027 0%, #00edff 52%, #e90027);
display: inline-block;
background-size: auto 200%;
background-position: 0 100%;
padding: 15px;
animation: Gradient 5s linear infinite forwards;
transition: all .6s ease;
}
#keyframes Gradient {
0% {
background-position: 0 0;
}
100% {
background-position: -200% 0;
}
}
<div class="bookParty">
<span class="skew"><h2>Book a Party</h2></span>
</div>
Working example here:
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background: radial-gradient(transparent, rgba(0, 0, 0, .6)), linear-gradient(to bottom right, #ECECEC 50%, transparent 50%, #fff 50%);
height: 100vh;
width: 100vw;
}
.bookParty {
-webkit-animation: Gradient 3s linear infinite;
-z-animation: Gradient 3s linear infinite;
-o-animation: Gradient 3s linear infinite;
animation: Gradient 3s linear infinite alternate;
background: linear-gradient(to right, #e90027 0%, #00edff 52%, #e90027);
background-size: 200% 200%;
padding: 25px;
border-radius: 5px;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
font-size: 3vw;
font-weight: bold;
text-shadow: 0 8px 16px rgba(0, 0, 0, .3);
color: #fff;
}
#keyframes Gradient {
to {
background-position: 50vw;
}
}
<div class="bookParty">
<span>Book a Party</span>
</div>

Animated pseudo elements and z-index - works in Firefox but not in Chrome

In firefox pseudo elements are behind the div (this is what I wanted to achieve) but in chrome they are on top. Is this a bug in chrome? Anyone knows how to fix this? Adding z-index to the div didn't help me to solve this problem.
I've also tried to apply some styles to div:hover but then when I hover over the div element it falls behind pseudo elements (in Firefox, in Chrome pseudo elements are already on top).
Demo on codepen https://codepen.io/mariuszdaniel/pen/rzdyRV?editors=1100
#keyframes spin {
from {
transform: rotate(0turn)
translateY(-100%) translateY(50%)
rotate(1turn)
}
to {
transform: rotate(1turn)
translateY(-100%) translateY(50%)
rotate(0turn);
}
}
#keyframes spin-rev {
from {
transform: rotate(1turn)
translateY(-100%) translateY(50%)
rotate(0turn)
}
to {
transform: rotate(0turn)
translateY(-100%) translateY(50%)
rotate(1turn);
}
}
#keyframes glow {
from {
filter: blur(100px);
opacity: 0.8
}
to {
filter: blur(200px);
opacity: 0.4;
}
}
.path {
width:300px;
height: 300px;
padding: 20px;
margin: 100px auto;
border-radius: 50%;
background-image: url(https://unsplash.it/300);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
transition: transform 0.5s, box-shadow 0.5s;
}
.path:hover {
transform: scale(1.25);
box-shadow: 0 0 50px 0 #3333;
}
.path::before, .path::after {
content: "";
position:aboslute;
display: block;
width: 75%;
height: 75%;
margin: 25% auto 0;
border-radius: 50%;
/*filter: blur(100px); */
/*opacity: 0.5;*/
}
.path::before {
/*mix-blend-mode: hue;*/
z-index: -200;
background-color: #21D4FD;
background-image: linear-gradient(19deg, #21D4FD 0%, #B721FF 100%);
animation: spin 9s infinite /*alternate*/ linear, glow 3s infinite alternate linear;
}
.path::after {
margin-top: -100%;
z-index: -100;
background-color: #08AEEA;
background-image: linear-gradient(0deg, #08AEEA 0%, #2AF598 100%);
animation: spin-rev 6s infinite /*alternate-reverse*/ linear, glow 6s infinite alternate linear;
}
<div class="path"></div>

Transform Origin for text?

I'm currently trying to change both my background and my text color at the same time, from left to right. Like the background is doing it.
But, since transform origin does not work in text, I would like to know how (if possible) can I achieve this?
Here is a demo of what I could do:
.container {
background-color: gray;
height: 200px;
width: 50vw;
margin: 5vw;
opacity: 0.5;
border-left: 5px solid black;
position: relative;
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
-webkit-transform-origin: left;
transform-origin: left;
}
.container:hover {
color: white;
}
.container:hover::after {
width: 100%;
content: '';
}
.container::after {
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0%;
opacity: 0.5;
background-color: darkgreen;
}
.container .text {
display: block;
text-align: center;
font-size: 2.3em;
font-family: 'Roboto';
line-height: 2.5em;
}
<div class="container">
<div class="text">Change Text at the same time</div>
</div>
I achieved the effect by adding the following properties to .text:
background: linear-gradient(to left, black 0%, black 50%, white 50%, white 100%); // half black and half white background
background-clip: text; // clip the background in the shape of the text
color: transparent; // remove the color of the text
background-size: 200%; // double the size of the background
background-position: 100% 0; // move the background to show just the black color
Now to make the color change effect - move the background position to 0% to show the white color:
.container:hover .text {
background-position: 0;
}
Demo
.container {
background-color: gray;
height: 200px;
width: 50vw;
margin: 5vw;
opacity: 0.5;
border-left: 5px solid black;
position: relative;
-webkit-transition: 0.5s all ease;
transition: 0.5s all ease;
transform-origin: left;
}
.container:hover .text {
background-position: 0;
}
.container:hover::after {
width: 100%;
content: '';
}
.container::after {
transition: all 1s ease;
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0%;
opacity: 0.5;
background-color: darkgreen;
}
.container .text {
transition: all 1s ease;
display: block;
text-align: center;
font-size: 2.3em;
font-family: 'Roboto';
line-height: 2.5em;
background: linear-gradient(to left, black 0%, black 50%, white 50%, white 100%);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
background-size: 200%;
background-position: 100% 0;
}
<div class="container">
<div class="text">Change Text at the same time</div>
</div>
Browsers support:
Supported by Firefox, Chrome, and other webkit browsers.
Not supported by IE and Edge, as they don't support background-clip: text;

Resources