简体   繁体   中英

smooth opacity transition on an element with a filter applied

so I have a DIV with a blur filter applied to it. I am trying to "fade in" the DIV using CSS opacity (0 to 1) over a one second transition. The DIV does fade in, but it is very glitchy. I tried increasing the transition time, but it still glitches between blurred states. any idea how to smooth this transition? here is the code I am using:

SVG code:

<svg>
<filter id="blur-effect-1">
<feGaussianBlur stdDeviation="15" />
</filter>
</svg>

CSS code:

#testdiv
{
background: url('images/background-buildpresentation.jpg') fixed;
border-radius: 30px;
color: white;
filter: url(#blur-effect-1);
font-family: arial;
font-size: 40px;
height: 80%;
left: 10%;
opacity: 0;
position: absolute;
top: 10%;
transition: all 1s;
width: 80%;
}

HTML code:

<div id="testdiv">Display some text here</div>

JavaScript creates the transition:

setTimeout(function(){testdiv.style.opacity="1"},2000);

This may just be a limitation of the browser. I am testing in firefox 27 currently. thanks in advance.

doug

A stdDeviation of 15 is very large. That is the equivalent to a blur radius of 45. That means for every pixel in the div, it is doing 4 x (45 + 45)^2 multiplications. For a div that is 80% of the page (I am guessing from your CSS), that could be something like 800 x 800 x 4 x 90^2. Assuming my maths is correct, that's over 20 billion calculations per step of the opacity transition. Even with graphics hardware, that probably isn't going to be that smooth.

There are possible alternatives. You could draw the blurred div into a canvas and then fade that. See

converting div and its associated elements to canvas jquery?

or

http://html2canvas.hertzen.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM