简体   繁体   English

应用了滤镜的元素上的平滑不透明过渡

[英]smooth opacity transition on an element with a filter applied

so I have a DIV with a blur filter applied to it. 所以我在DIV上应用了模糊滤镜。 I am trying to "fade in" the DIV using CSS opacity (0 to 1) over a one second transition. 我试图在一秒钟的过渡中使用CSS不透明度(从0到1)“淡入” DIV。 The DIV does fade in, but it is very glitchy. DIV确实会淡入,但是非常毛刺。 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代码:

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

CSS code: CSS代码:

#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: HTML代码:

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

JavaScript creates the transition: JavaScript创建过渡:

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

This may just be a limitation of the browser. 这可能只是浏览器的限制。 I am testing in firefox 27 currently. 我目前在Firefox 27中进行测试。 thanks in advance. 提前致谢。

doug 道格

A stdDeviation of 15 is very large. stdDeviation 15非常大。 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. 这相当于模糊半径为45。这意味着对于div中的每个像素,它都将进行4 x(45 + 45)^ 2的乘法。 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. 对于占页面80%的div(我从您的CSS猜测),可能类似于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. 假设我的数学是正确的,那么不透明度转换的每个步骤要进行200亿次以上的计算。 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. 您可以将模糊的div绘制到画布中,然后使其褪色。 See 看到

converting div and its associated elements to canvas jquery? 将div及其相关元素转换为canvas jquery?

or 要么

http://html2canvas.hertzen.com/ http://html2canvas.hertzen.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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