[英]Image blob loading and css filters
Is it somehow possible to do something, not on load, but on image render in javascript? 是否有可能做一些事情,而不是在加载时,而是在javascript中渲染图像?
We have a following scenario: 我们有以下情形:
image.src = url;
image.src = url;
onload
listener, which sets a css filter for an image, different for each image. onload
侦听器,该侦听器为图像设置css过滤器,每个图像均不同。 Sometimes, especially for bigger images, there is a blink of an unfiltered image, and than a properly filtered image is displayed. 有时,特别是对于较大的图像,会出现未过滤图像的闪烁,然后显示正确过滤的图像。 On the other hand, setting the filter during the
src
assign causes the previously displayed image to flicker for a moment with a wrong filter. 另一方面,在
src
分配期间设置滤镜会导致先前显示的图像在滤镜错误的情况下闪烁片刻。 This happens in all major browsers. 在所有主要的浏览器中都会发生这种情况。
Any ideas how to make it silky smooth? 有什么想法如何使它柔滑吗? :)
:)
Try this. 尝试这个。
Before assigning the src
, hide the img
contents, by changing either display
or visibility
attribute. 在分配
src
之前,请通过更改display
或visibility
属性来隐藏img
内容。
display: none; //OR visibility: hidden;
The blobs url is passed to the image element image.src = url;
Blob网址会传递到图片元素
image.src = url;
. 。
This would load the img
content but it would be invisible. 这将加载
img
内容,但将不可见。
Now apply the CSS filters as per your requirement. 现在,根据您的要求应用CSS过滤器。 The
img
would be invisible so there would be no flicker or anything. img
将是不可见的,因此不会出现闪烁或其他任何情况。
Now change the display
or visibility
attribute back. 现在改回
display
或visibility
属性。
display: initial; //OR visibility: visible;
Additionally, if you are using JQuery or some other library you can animate the transition using functions such as fadeIn()
, slideDown()
, so that it all appears super smooth and fancy. 另外,如果您使用的是JQuery或其他库,则可以使用诸如
fadeIn()
, slideDown()
类的动画效果对过渡进行动画处理,从而使它们看起来都非常流畅和漂亮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.