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>
Related
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 have logo in my website, it is grayscaled on hover i want it to be colored smoothly. it is working but not smoothly. i am using CSS transition.
This is my code
<img alt="TT ltd logo" src="./img/tt-logo.png" class="tt-logo" />
<style>
img.tt-logo {
filter: grayscale(1);
transition: grayscale 0.5s;
}
img.tt-logo:hover {
filter: grayscale(0);
}
</style>
Try do it this way:
img.tt-logo {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
filter: grayscale(100%);
transition: all 0.5s ease;
}
img.tt-logo:hover {
-webkit-filter: grayscale(0%);
-moz-filter: grayscale(0%);
filter: grayscale(0%);
}
and every image has its own alt, you can use it without using img.class:
img[alt="TT ltd logo"] {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
filter: grayscale(100%);
transition: all 0.5s ease;
}
img[alt="TT ltd logo"]:hover {
-webkit-filter: grayscale(0%);
-moz-filter: grayscale(0%);
filter: grayscale(0%);
}
in this case class is extra
Animating a filter takes a lot of computation and might hurt performance in some browsers.
You can get better performance by animating the opacity of a grayscale image to reveal a full-color image beneath it.
Here's an example.
With the current state of browsers, you could go for the example below, short and simple.
Modern browsers nowadays support the grayscale CSS attribute and if you're only transitioning one attribute, best reference one attribute instead of all attributes.
img {
grayscale: 1;
transition: filter .23s ease-in-out;
}
img:hover {
grayscale: 0;
}
Sources:
Animatable CSS properties
grayscale attribute
Timings on transitions
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
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).
If I use this code
#-webkit-keyframes blurMe{
0% {
-webkit-filter: blur(5px);
}
100% {
-webkit-filter: blur(0px);
}
}
It will work.
But if I add this:
0% {
-webkit-filter: blur(5px);
-webkit-transform: scale(4,4);
}
100% {
-webkit-filter: blur(0px);
-webkit-transform: scale(1,1);
}
The element I use this keyframes only show scale (from 4 to 2), the blur always be 4px;
that means when getting 100%, -webkit-filter: blur(0px) didn't work. Why?
(using Chrome).
Most probably this is a Chrome bug. But you should realise that when you are three unstable (prefixed) features together, you'll get a result that is unstable^3.
As a workaround you may use two elements and apply different animation to each one:
<div class="outer">
<div class="inner"></div>
</div>
.outer,
.inner {
-webkit-animation: 3s infinite;
}
.outer {
-webkit-animation-name: scaleMe;
}
.inner {
width: 100%;
height: 100%;
-webkit-animation-name: blurMe;
}
#-webkit-keyframes blurMe {
from { -webkit-filter: blur(5px); }
to { -webkit-filter: blur(0); }
}
#-webkit-keyframes scaleMe {
from { -webkit-transform: scale(4); }
to { -webkit-transform: scale(1); }
}
Demo: http://jsfiddle.net/YNLhu/2/