I have a solid background that I want to alternate the brightness of on a loop using CSS on Chrome. The background will change to match a user's profile so it won't always be the same color.
As an example: The background could start out red, transition to a pinkish color and then back to red after a second.
Another example: The background could start out blue, transition to a baby blue color and then back to blue after a second.
I can accomplish the color effect by adjusting the brightness and contrast of the color but I don't know how to do this with webkit.
How can I alternate the brightness and contrast using CSS and webkit?
UPDATE:
You can animate brightness and contrast the same way, but I'm not sure how you would like to achieve pink with that.
Filters require the prefix -webkit-
#keyframes example {
0% {
filter: brightness(1);
filter: contrast(1);
-webkit-filter: brightness(1);
-webkit-filter: contrast(1);
}
50% {
filter: brightness(0.4);
filter: contrast(0.4);
-webkit-filter: brightness(0.4);
-webkit-filter: contrast(0.4);
}
100% {
filter: brightness(1);
filter: contrast(1);
-webkit-filter: brightness(1);
-webkit-filter: contrast(1);
}
}
Fiddle
Why use brightness and contrast when you can just tween between the colors?
div {
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
#keyframes example {
from {background: red;}
to {background: pink;}
}
Fiddle
Or if you want to loop it without the blink
#keyframes example {
0% {background: red;}
50% {background: pink;}
100% {background: red;}
}
Fiddle
Related
Original Intention
I want to make image slideshow, using opacity and blur during image transition.
Result
White border appears on the edge, so I looked into SO, and found this answer:
https://stackoverflow.com/a/42963980/11769757
Everything works well in Firefox, but doesn't work in Chrome.
There is still white edge during transition no matter how I increase scale.
It looks like chrome ignores area outside the browser window.
JSFiddle example
[Image1] In chrome, there are white edges
[Image2] but in firefox, it works well
However, when I put blur on image directly (not in animation), white edge dissapears from both browser.
So maybe my animation is wrong but I can't find where is the mistake.
Code
I put two div with background image, and put class to each for crossfading between images.
HTML
<div style="{'background-image': `url(image1)`}" class="full blur-leave-active"/>
<div style="{'background-image': `url(image2)`}" class="full blur-enter-active"/>
CSS
.full {
background-position: center;
background-size: cover;
position: absolute;
width: 100%;
height: 100%;
transform: scale(1.2);
}
.blur-leave-active {
animation: blur-animation-out 4s;
}
.blur-enter-active {
animation: blur-animation-in 4s;
}
#keyframes blur-animation-out {
0% {
filter: blur(0);
opacity: 1;
}
30% {
filter: blur($blur-width);
opacity: 0.8;
}
50% {
opacity: 0;
}
}
#keyframes blur-animation-in {
0% {
filter: blur($blur-width);
opacity: 0;
}
50% {
opacity: 1;
filter: blur($blur-width);
}
80% {
filter: blur(0);
}
}
Question
Am I missing something?
How to make filter blur animations with window full size image without white borders in Chrome?
I understand this animation should work on SVGs as it does on HTML elements but obviously I am wrong!
How do I achieve this effect with CSS on an SVG? Fiddle here.
div {
background: blue;
width: 400px;
height: 100px;
animation-name: example;
animation-duration: 4s;
animation-iteration-count: infinite;
}
#keyframes example {
0% {
filter: brightness(1);
filter: contrast(1);
-webkit-filter: brightness(1);
-webkit-filter: contrast(1);
}
50% {
filter: brightness(0.1);
filter: contrast(0.1);
-webkit-filter: brightness(0.1);
-webkit-filter: contrast(0.1);
}
100% {
filter: brightness(1);
filter: contrast(1);
-webkit-filter: brightness(1);
-webkit-filter: contrast(1);
}
}
Change the div from css to svg . It works for me.
Or if you want to see both the div and svg, just add div, svg { css code..}
Example: http://jsfiddle.net/4ebv7jzd/1/
I am facing a challenge to make a dynamic 'hinting' system. I would like to make an element blink using only CSS. Not sure if it even possible. Normally you should define the begin and end color of your animation (update: This is not true.), but because I would like to let it work on multiple background colours this isn't an option.
I have tried a number of options and Google queries (inherit, currentColor etc.) but all it does is go from white/transparent to #ef9633.
Anyone got some options I could try?
Code:
#keyframes nk-hint {
0% { background-color: #XXX; }
50% { background-color: #ef9633; }
100% { background-color: #XXX; }
}
#-webkit-keyframes nk-hint {
0% { background-color: #XXX; }
50% { background-color: #ef9633; }
100% { background-color: #XXX; }
}
Thanks allot already!
The answer was simpler than I thought. You can just remove the 0% and 100% and it works fine on all major browser. Still need to test this on iOS and IE.
It's safe to say you don't need to set a begin and/or end colour.
#keyframes nk-hint {
50% { background-color: #ef9633; }
}
#-webkit-keyframes nk-hint {
50% { background-color: #ef9633; }
}
animation-fill-mode can do what you want, unless you need to support IE < 9. http://www.w3schools.com/cssref/css3_pr_animation-fill-mode.asp
If you need IE 9 support, then I believe you're stuck with Javascript for the animation unfortunately.
Ok then, you could make the changes as shown below.
.your-selector {
background-color: red;
-webkit-animation: nk-hint 3s; /* Chrome, Safari, Opera */
-webkit-animation-iteration-count: 1; /* Chrome, Safari, Opera */
-webkit-animation-fill-mode: forwards; /* Chrome, Safari, Opera */
animation: nk-hint 3s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#-webkit-keyframes nk-hint {
0% {background-color: #XXX;}
50% {background-color: #ef9633;}
100% {background-color: #XXX;}
}
#keyframes nk-hint {
0% {background-color: #XXX;}
50% {background-color: #ef9633;}
100% {background-color: #XXX;}
}
The keyframes will remain the same.
I have this code:
.blur {
-webkit-animation: blur 5s ;
-webkit-animation-fill-mode: forwards;
}
#-webkit-keyframes blur {
0% { -webkit-filter: blur(0px); }
0% { -webkit-filter: blur(1px); }
50% { -webkit-filter: blur(5px); }
60% { -webkit-filter: blur(5px); }
100% {
opacity: 0;
}
}
<img src="http://placehold.it/350x150" class="blur" />
Basically I have an image and the effect that I want is to fade it in slowly, blur it and then fade it out. But when it blurs I want it to stay there for few seconds and then fade out the picture. Could you please help me out? Thanks
Thinking in terms of keyframes, you want to let the animation know when to start fading. Otherwise it assumes you're working towards your final opacity for the duration of the animation.
To prevent this, pin your opacity at 1 just prior to beginning the fade. You could try something like this:
.blur {
-webkit-animation: blur 5s ;
-webkit-animation-fill-mode: forwards;
}
#-webkit-keyframes blur {
0% { -webkit-filter: blur(0px); }
0% { -webkit-filter: blur(1px); }
50% { -webkit-filter: blur(5px); }
60% { -webkit-filter: blur(5px); }
90% {
-webkit-filter: blur(5px);
opacity: 1;
}
100% {
opacity: 0;
}
}
<img src="http://placehold.it/350x150" class="blur" />
The above code only starts the fadeout in the last 10% of the animation - otherwise, the blurred image hangs around. You can nudge this duration with both your .blur duration and your keyframe percentages (larger percentage spread = longer time before fading out).
I'm creating a modal pop-up that alerts the user, and overlays on the page.
I'm trying to make it so that the background is blurred (thus content on page is obscured) but the modal-pop-up is clear.
Here is an example, the modal fades in after several seconds. I have applied filter: blur to the .modal-newsletter-wrap which is the wrapper that sits full across the page. My intention was that the text and the cat image on the page would be blurred, but they are still crisp: http://codepen.io/anon/pen/Ggzxdz
Also, despite having filter: blur(0); set on the inner div .modal-newsletter it's still inheriting the blur of the wrapper div.
.modal-newsletter-wrap {
background-color:rgba(243,243,232,0.5);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
filter: blur(5px);
}
.modal-newsletter{
-webkit-filter: blur(0);
-moz-filter: blur(0);
-o-filter: blur(0);
-ms-filter: blur(0);
filter: blur(0);
}
.modal-newsletter is child of .modal-newsletter-wrap, so if you set blur filter on .modal-newsletter-wrap it will of-course apply to .modal-newsletter, no matter if you set blur(0) on child element .modal-newsletter.
you can set the blur on<p><p>, which now contains your page body(including cat and all stuff), so the blur is not carried to the modal popup.
See this codepen, you will need to set the style for blur on your content, using javascript when the modal opens.
Another solution would be to put an overlay on the page , which is not realted to (not parent of) .modal-newsletter-wrap, and add blur to it. Like this
wrap all the contents except the overlay in a common parent element (e.g a <main> element) then run a blur animation after 5 seconds
http://codepen.io/anon/pen/EarEzo
#-webkit-keyframes blur {
0% { -webkit-filter: blur(0px); }
100% { -webkit-filter: blur(5px); }
}
#-moz-keyframes blur {
0% { -moz-filter: blur(0px); }
100% { -moz-filter: blur(5px); }
}
#keyframes blur {
0% { filter: blur(0px); }
100% { filter: blur(5px); }
}
main {
-webkit-animation: blur 1s linear 5s 1 forwards;
-moz-animation: blur 1s linear 5s 1 forwards;
animation: blur 1s linear 5s 1 forwards;
}
In this example http://codepen.io/anon/pen/gbqeVV I've also activated the close action via CSS :target pseudoclass. If the overlay element is a sibling of the content wrapper then you could transform the “close” label into a link as in the example, then add this style
#close-layer:target {
display: none;
}
#close-layer:target ~ main {
-webkit-animation: none;
-moz-animation: none;
animation: none;
-webkit-filter: blur(0);
-moz-filter: blur(0);
filter: blur(0);
}
The same effect can be also achieved without setting an hash, e.g. using an hidden checkbox and the :checked pseudoclass: http://codepen.io/anon/pen/XJOqJV
#closeoverlay { display: none; }
#closeoverlay:checked ~ .modal-newsletter-wrap {
display: none;
}
#closeoverlay:checked ~ main {
-webkit-animation: none;
-moz-animation: none;
animation: none;
-webkit-filter: blur(0);
-moz-filter: blur(0);
filter: blur(0);
}
Another approach is just one line of css: backdrop-filter: blur(1rem);:
<div class="some-background">
<div style="backdrop-filter: blur(1rem);"></div>
</div>