Hm, if that's the case, then theoretically this component can be easily improved to support any DOM container (not just images) by just polyfilling filter: with native or SVG.
I dunno about that. <img> has a pretty direct analog in SVG that you could create by adding it (and the SVG container) to the DOM in script. Arbitrary markup would probably be best to render into a canvas.
Of course, you could always just force IE9 mode... ;)
But why write this as a React component, when a plain javascript implementation would do fine (in view of compatibility with existing code, which may not be using React)? Am I missing something?
I personally don't like this style. It makes it harder to read the code. If someone misses that `var Blur = this` line, they could get confused and either not use it, or use it incorrectly.
Instead, since you're using ES6, I suggest using the fat arrow:
(I'm used to writing Coffeescript instead of ES6, so sorry if minor syntax details are wrong.)
This is largely a stylistic choice. You can feel free to do things however you want, and if it works, it works. But generally I prefer to make sure things are really clear, and that the Javascript features aren't obscured.
By using arrow functions it's simply implied that the top level context is always being used. You don't have to define what "this" is, since it's always "this".
Suggestion: Add support for frosted glass since it's an easy extension.
You would only need another parameter for an RGBA color for "tint". Then draw over the blurred area with this color.
For example, setting tint to rgba(255,255,255,0.15) will look like the iOS style frosted effect. Varying the rgb and alpha can show other interesting options.
17 comments
[ 3.1 ms ] story [ 44.5 ms ] threadIs there some advantage I'm missing?
http://blogs.msdn.com/b/ie/archive/2011/10/14/svg-filter-eff...
Edit: to clarify, the image would need to be moved into the SVG (which could be a simple DOM manipulation of the original <img> tag).
Of course, you could always just force IE9 mode... ;)
I noticed that you're caching `this` as a variable:
And it looks like you're doing so to avoid scope problems in anonymous functions: I personally don't like this style. It makes it harder to read the code. If someone misses that `var Blur = this` line, they could get confused and either not use it, or use it incorrectly.Instead, since you're using ES6, I suggest using the fat arrow:
(I'm used to writing Coffeescript instead of ES6, so sorry if minor syntax details are wrong.)This is largely a stylistic choice. You can feel free to do things however you want, and if it works, it works. But generally I prefer to make sure things are really clear, and that the Javascript features aren't obscured.
I think it makes it much easier to read the code. Assigning it to a variable gives a nice, short description of what you're actually working with.
Suggestion: Add support for frosted glass since it's an easy extension.
You would only need another parameter for an RGBA color for "tint". Then draw over the blurred area with this color.
For example, setting tint to rgba(255,255,255,0.15) will look like the iOS style frosted effect. Varying the rgb and alpha can show other interesting options.