TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: React component for blurred backgrounds

25 pointsby javierbyteabout 10 years ago

7 comments

morleyabout 10 years ago
Nice work!<p>I noticed that you&#x27;re caching `this` as a variable:<p><pre><code> var Blur = this, </code></pre> And it looks like you&#x27;re doing so to avoid scope problems in anonymous functions:<p><pre><code> Blur.img.onload = function(){ stackBlurImage( Blur.img, Blur.canvas, blurRadius, Blur.width, Blur.height) }; </code></pre> I personally don&#x27;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.<p>Instead, since you&#x27;re using ES6, I suggest using the fat arrow:<p><pre><code> this.img.onload = () =&gt; { stackBlurImage(this.img, this.canvas, blurRadius, this.width, this.height); }; </code></pre> (I&#x27;m used to writing Coffeescript instead of ES6, so sorry if minor syntax details are wrong.)<p>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&#x27;t obscured.
评论 #9318804 未加载
fitterabout 10 years ago
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?<p>Is there some advantage I&#x27;m missing?
评论 #9318382 未加载
WhitneyLandabout 10 years ago
Nice work.<p>Suggestion: Add support for frosted glass since it&#x27;s an easy extension.<p>You would only need another parameter for an RGBA color for &quot;tint&quot;. Then draw over the blurred area with this color.<p>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.
antidailyabout 10 years ago
I&#x27;m not smart enough to know how good the performance is on this. Decent? Better than CSS?
untilHellbannedabout 10 years ago
Thanks for the contribution! Minor point: It would be nice if the demo&#x27;s slider would be draggable on mobile, iOS Safari can&#x27;t see it in action.
评论 #9319005 未加载
escusadoabout 10 years ago
Eaaaa el niño! :D
flockflockabout 10 years ago
...