Is there a way to apply a “blur” effect on a background image in Javascript/jQuery?
[edit] By “blur” I mean a Gaussian/Motion blur not a drop shadow 🙂
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The simplest, most cross-browser-friendly way to do this will be to create blurred and non-blurred versions of your background image ahead of time, and use JavaScript to swap the blurred version in when you want to. Something like:
Edit: It’s a bit of a cop-out, but all you need to do is create a new image element for Pixastic to operate on. Since Pixastic uses a canvas anyway, you can let the library do the work for you, and then just call
toDataURL()to get a URL string. Then, pass that string back into thebackground-imageCSS.Very basic demo here. Tested in Chrome, Firefox.
Notes:
canvas, as per the spec. This is why my example image is jsbin’s favicon, and not an image that’s bigger/more interesting/from anywhere else.toDataURL()so the browser doesn’t have to repeat its work. I don’t know howtoDataURL()works under the hood so this might not be entirely straightforward.Happy blurring!