I need to dynamically blur the image on my page, but only along one axis ( Y in particular). So here are my requirements:
- It should be done live (I canβt pre-paint the blurry version of the image)
- As I said, only on the
Y axis (for example, motion blur, but vertical) - Need to animate
- Should work in IE9 +
My first thought was to use a simple CSS filter:
img { filter: blur(20px); }
I can animate this by adding a transition ( transition: filter 0.2s linear ), but it only creates Gaussian blurring, which I don't want. The syntax does not support something like filter: blur(0 10px); to limit the blur to only one axis.
Then I read that the blur filter (among others) is actually just a shorthand for the SVG filter, which you can write manually if you want. So I created an SVG called filter.svg that indicates 20px blur only along the Y axis ( 0 20 ):
<?xml version="1.0" standalone="no"?> <svg width="1" height="1" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <filter id="blur"> <feGaussianBlur in="SourceGraphic" stdDeviation="0 20" /> </filter> </defs> </svg>
And applied it like this:
img { filter: url("filter.svg#blur"); }
And that works fine ... but only in Firefox. Safari / Chrome does not support url() as the value for filter . Also, I cannot animate it because the value is a URL, not a number, so transition does not work.
Among other things, I do not think that any of these approaches works in IE9 .
So: is there a way to do what I'm trying to do? I looked at using canvas as an alternative, but can't find any examples of blur that goes in only one direction.
daGUY source share