News for hackers. Stuff that matters.
Re:Show HN: React component for blurred backgrounds by morley on Friday April 03, 2015 @05:05PM (#9318527)
Nice work!

I noticed that you're caching `this` as a variable:

  var Blur = this,
And it looks like you're doing so to avoid scope problems in anonymous functions:

  Blur.img.onload = function(){
      stackBlurImage( Blur.img, Blur.canvas, blurRadius, Blur.width, Blur.height)
  };
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:

  this.img.onload = () => {
    stackBlurImage(this.img, this.canvas, blurRadius, this.width, this.height);
  };
(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.

Re:Show HN: React component for blurred backgrounds by simplify on Friday April 03, 2015 @05:50PM (#9318804)
> It makes it harder to read the code

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.

Re:Show HN: React component for blurred backgrounds by lfuller on Friday April 03, 2015 @07:05PM (#9319111)
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".
Re:Show HN: React component for blurred backgrounds by fitter on Friday April 03, 2015 @04:26PM (#9318271)
Does this need to be a canvas-scribbling React component when you can do this with better performance using a couple of lines of CSS filters?

Is there some advantage I'm missing?

Re:Show HN: React component for blurred backgrounds by javierbyte on Friday April 03, 2015 @04:44PM (#9318382)
Author here. As far as I know there is no way to do blur with CSS in IE10+ https://github.com/Schepp/CSS-Filters-Polyfill#a-word-regard... so we must use canvas to be cross-browser.
Re:Show HN: React component for blurred backgrounds by spdustin on Friday April 03, 2015 @04:59PM (#9318477)
You can. SVG Filters are supported.

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).

Re:Show HN: React component for blurred backgrounds by fitter on Friday April 03, 2015 @05:05PM (#9318524)
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.
Re:Show HN: React component for blurred backgrounds by spdustin on Friday April 03, 2015 @05:34PM (#9318709)
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... ;)

Re:Show HN: React component for blurred backgrounds by javierbyte on Friday April 03, 2015 @05:03PM (#9318510)
Thank you! I will investigate and compare.
Re:Show HN: React component for blurred backgrounds by amelius on Friday April 03, 2015 @07:14PM (#9319136)
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?
Re:Show HN: React component for blurred backgrounds by javierbyte on Saturday April 04, 2015 @01:19AM (#9319992)
Yeah, I was also thinking in create a non-react version, but a separate react version would still be needed since we are doing DOM manipulation.
Re:Show HN: React component for blurred backgrounds by WhitneyLand on Friday April 03, 2015 @05:38PM (#9318733)
Nice work.

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.

Re:Show HN: React component for blurred backgrounds by antidaily on Friday April 03, 2015 @04:21PM (#9318238)
I'm not smart enough to know how good the performance is on this. Decent? Better than CSS?
Re:Show HN: React component for blurred backgrounds by untilHellbanned on Friday April 03, 2015 @05:14PM (#9318585)
Thanks for the contribution! Minor point: It would be nice if the demo's slider would be draggable on mobile, iOS Safari can't see it in action.
Re:Show HN: React component for blurred backgrounds by javierbyte on Friday April 03, 2015 @06:39PM (#9319005)
Sure! Fixing right now.
Re:Show HN: React component for blurred backgrounds by escusado on Friday April 03, 2015 @07:36PM (#9319221)
Eaaaa el niño! :D
Re:Show HN: React component for blurred backgrounds by flockflock on Friday April 03, 2015 @04:56PM (#9318457)
...