Fork me on GitHub

Image Blur Plugin

Ultra small plugin (4kb minified, 1.5kb gzipped) for Blurring images

Install this plugin with Bower:

bower install background-blur

Or manually:

<script src="jquery.min.js"></script>
<script src="background-blur.min.js"></script>

Create a container which will contain the blurred image:

<div id='some-element'></div>

Then create a blurred image in that container:

$('#some-element').backgroundBlur({
    imageURL : 'http://URL-of-the-image',
    blurAmount : 50,
    imageClass : 'bg-blur'
});

OR Create a blurred image and fade it in:

$('#some-element').backgroundBlur({
    imageURL : 'http://URL-of-the-image',
    blurAmount : 50,
    imageClass : 'bg-blur'
    duration: 1000, // If the image needs to be faded in, how long that should take
    endOpacity : 1 // Specify the final opacity that the image will have
});

OR Create a blurred image, fade it in and switch to another image:

// Initialize the blur
$('#some-element').backgroundBlur({
    imageURL : 'http://URL-of-the-image',
    blurAmount : 50,
    imageClass : 'bg-blur'
    duration: 1000, // If the image needs to be faded in, how long that should take
    endOpacity : 1 // Specify the final opacity that the image will have
});

//Switch the image
$('#some-element').backgroundBlur('http://URL-of-another-image');

Avatar-based backgrounds (click):

@msurguy
@gt
@mijustin

Code:

$avatarHolderEl.backgroundBlur({
    imageURL : avatars[0],
    blurAmount : 50,
    imageClass : 'avatar-blur'
});

Tinted overlays:

$tintedHolderEl.backgroundBlur({
    imageURL : 'url-of-the-image',
    blurAmount : 10,
    imageClass : 'tinted-bg-blur',
    overlayClass : 'tinted-bg-overlay',
    duration: 1000,
    endOpacity : 1
});
.tinted-bg-blur {
    z-index: -2;
    opacity: 0;
    position: absolute;
    min-height: 100%;
    height: auto;
    display: block;
    top: 0;
    max-height: none;
    /* Add this CSS to remove transparent border around the image */
    left: -10%;
    width: 120%;
}

.tinted-bg-overlay {
    z-index: -1;
    position: absolute;
    width: 100%;
    height: 100%;
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjZWE0ZmNlIiBzdG9wLW9wYWNpdHk9IjAuOTYiLz4KICAgIDxzdG9wIG9mZnNldD0iNjclIiBzdG9wLWNvbG9yPSIjNmE1ZmMyIiBzdG9wLW9wYWNpdHk9IjAuMTciLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzJiNjdiYyIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
    background: -moz-linear-gradient(-45deg,  rgba(234,79,206,0.96) 0%, rgba(106,95,194,0.17) 67%, rgba(43,103,188,1) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, right bottom, color-stop(0%,rgba(234,79,206,0.96)), color-stop(67%,rgba(106,95,194,0.17)), color-stop(100%,rgba(43,103,188,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(-45deg,  rgba(234,79,206,0.96) 0%,rgba(106,95,194,0.17) 67%,rgba(43,103,188,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(-45deg,  rgba(234,79,206,0.96) 0%,rgba(106,95,194,0.17) 67%,rgba(43,103,188,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(-45deg,  rgba(234,79,206,0.96) 0%,rgba(106,95,194,0.17) 67%,rgba(43,103,188,1) 100%); /* IE10+ */
    background: linear-gradient(135deg,  rgba(234,79,206,0.96) 0%,rgba(106,95,194,0.17) 67%,rgba(43,103,188,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5ea4fce', endColorstr='#2b67bc',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */
}
 

Using video thubmbnail to create ambient background for a player (like on http://www.nbcnews.com/video):

  • Chrome
  • Firefox
  • Safari and Safari Mobile (iOS)
  • IE6, IE7, IE8 - blur is supported without animation (need to omit "duration" property in those browsers to make this plugin work, the problem will get fixed when Velocity.js issue gets fixed)
  • IE9, IE10, IE11
  • Android browsers
  • Possibly, more. Please let me know if some browser doesn't work

This plugin utilizes SVG filter to blur the image if SVG is supported by the browser (all except IE), otherwise the plugin creates an IMG tag and applies a special IE-only filter in CSS

Q: Why not simply use CSS 3 blur filter?
A:The browser support for SVG blur filter is much wider when it comes to older browsers.

If you are using Velocity.js animation library, the plugin will automatically detect its presence and make fade in/fade out animations more performant, especially on mobile. If Velocity is not present on the page, jQuery's "animate" is used

This plugin is released under MIT license, giving you permission to use for commercial and non-commercial projects