├── .gitignore ├── gulpfile.js ├── bower.json ├── package.json ├── readme.md ├── dist ├── background-blur.min.js └── background-blur.js ├── src └── background-blur.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | dist/video 4 | .DS_Store 5 | .idea 6 | npm-debug.log 7 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var uglify = require('gulp-uglify'); 3 | var rename = require('gulp-rename'); 4 | 5 | gulp.task('compress', function() { 6 | gulp.src('src/*.js') 7 | .pipe(gulp.dest('dist')) 8 | .pipe(uglify()) 9 | .pipe(rename({ 10 | extname: '.min.js' 11 | })) 12 | .pipe(gulp.dest('dist')) 13 | }); 14 | 15 | gulp.task('default', [ 'compress' ]); -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "background-blur", 3 | "version": "0.1.0", 4 | "authors": [ 5 | "Maks Surguy " 6 | ], 7 | "description": "Image blur plugin", 8 | "main": "dist/background-blur.min.js", 9 | "moduleType": [ 10 | "globals" 11 | ], 12 | "keywords": [ 13 | "velocity", 14 | "blur", 15 | "animation", 16 | "jquery", 17 | "plugin" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "node_modules", 23 | "bower_components", 24 | "test", 25 | "tests" 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "background-blur", 3 | "version": "0.1.3", 4 | "description": "jQuery Plugin for cross-browser blurring of images", 5 | "main": "dist/background-blur.min.js", 6 | "scripts": { 7 | "build": "gulp" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/msurguy/background-blur.git" 12 | }, 13 | "keywords": [ 14 | "Blur", 15 | "velocity", 16 | "animation", 17 | "jQuery plugin", 18 | "SVG" 19 | ], 20 | "author": "Maksim Surguy", 21 | "dependencies": { 22 | "jquery": ">=1.7.1" 23 | }, 24 | "license": "MIT", 25 | "devDependencies": { 26 | "gulp": "^3.9.0", 27 | "gulp-rename": "^1.2.2", 28 | "gulp-uglify": "^1.2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Background Blur Plugin 2 | 3 | Background Blur plugin is a cross browser jQuery plugin for blurring images. 4 | 5 | See http://msurguy.github.io/background-blur/ for documentation and demos 6 | 7 | ## Installation and Usage 8 | 9 | Install the plugin with Bower: 10 | 11 | `bower install background-blur` 12 | 13 | Or with NPM: 14 | 15 | `npm install background-blur` 16 | 17 | Or manually: 18 | ```javascript 19 | 20 | 21 | ``` 22 | 23 | Create a container which will contain the blurred image: 24 | 25 | ```html 26 |
27 | ``` 28 | Then create a blurred image in that container: 29 | 30 | ```javascript 31 | $('#some-element').backgroundBlur({ 32 | imageURL : 'http://URL-of-the-image', 33 | blurAmount : 50, 34 | imageClass : 'bg-blur' 35 | }); 36 | ``` 37 | 38 | OR Create a blurred image and fade it in: 39 | 40 | ```javascript 41 | $('#some-element').backgroundBlur({ 42 | imageURL : 'http://URL-of-the-image', 43 | blurAmount : 50, 44 | imageClass : 'bg-blur' 45 | duration: 1000, // If the image needs to be faded in, how long that should take 46 | endOpacity : 1 // Specify the final opacity that the image will have 47 | }); 48 | ``` 49 | 50 | OR Create a blurred image, fade it in and switch to another image: 51 | 52 | ```javascript 53 | // Initialize the blur 54 | $('#some-element').backgroundBlur({ 55 | imageURL : 'http://URL-of-the-image', 56 | blurAmount : 50, 57 | imageClass : 'bg-blur' 58 | duration: 1000, // If the image needs to be faded in, how long that should take 59 | endOpacity : 1 // Specify the final opacity that the image will have 60 | }); 61 | 62 | //Switch the image 63 | $('#some-element').backgroundBlur('http://URL-of-another-image'); 64 | ``` 65 | 66 | ## Browser Support: 67 | 68 | - Chrome 69 | - Firefox 70 | - Safari and Safari Mobile (iOS) 71 | - 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) 72 | - IE9, IE10, IE11 73 | - Android browsers 74 | 75 | Possibly, more. Please let me know if some browser doesn't work 76 | 77 | ## Under the hood: 78 | 79 | 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 80 | 81 | **Q:** Why not simply use CSS 3 blur filter? 82 | **A:** The browser support for SVG blur filter is much wider when it comes to older browsers. 83 | 84 | **Velocity.js** support: 85 | 86 | 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 instead. 87 | 88 | ## Where is this used? 89 | 90 | This plugin is currently used on http://www.nbcnews.com/video 91 | 92 | Have questions / suggestions or using the plugin? Please reach out on Github or Twitter at http://twitter.com/msurguy 93 | 94 | ## LICENSE 95 | 96 | This plugin is released under MIT license, giving you permission to use for commercial and non-commercial projects. 97 | -------------------------------------------------------------------------------- /dist/background-blur.min.js: -------------------------------------------------------------------------------- 1 | !function(t){"use strict";function e(e){return this.each(function(){var i=t(this),n=i.data("plugin.backgroundBlur"),o=t.extend({},r.DEFAULTS,i.data(),"object"==typeof e&&e);n||i.data("plugin.backgroundBlur",n=new r(this,o)),"fadeIn"===e?n.fadeIn():"fadeOut"===e?n.fadeOut():"string"==typeof e&&n.generateBlurredImage(e)})}var i=function(){for(var t,e=3,i=document.createElement("div"),n=i.getElementsByTagName("i");i.innerHTML="",n[0];);return e>4?e:t}(),n=function(){return"_"+Math.random().toString(36).substr(2,9)},o={svgns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",createElement:function(t,e){var i=document.createElementNS(o.svgns,t);return e&&o.setAttr(i,e),i},setAttr:function(t,e){for(var i in e)"href"===i?t.setAttributeNS(o.xlink,i,e[i]):t.setAttribute(i,e[i]);return t}},r=function(e,i){this.internalID=n(),this.$element=t(e),this.$width=this.$element.width(),this.$height=this.$element.height(),this.element=e,this.options=t.extend({},r.DEFAULTS,i),this.$overlayEl=this.createOverlay(),this.$blurredImage={},this.useVelocity=this.detectVelocity(),this.attachListeners(),this.generateBlurredImage(this.options.imageURL)};r.VERSION="0.1.1",r.DEFAULTS={imageURL:"",blurAmount:10,imageClass:"",overlayClass:"",duration:!1,opacity:1},r.prototype.detectVelocity=function(){return!!window.jQuery.Velocity},r.prototype.attachListeners=function(){this.$element.on("ui.blur.loaded",t.proxy(this.fadeIn,this)),this.$element.on("ui.blur.unload",t.proxy(this.fadeOut,this))},r.prototype.fadeIn=function(){this.options.duration&&this.options.duration>0&&(this.useVelocity?this.$blurredImage.velocity({opacity:this.options.opacity},{duration:this.options.duration}):this.$blurredImage.animate({opacity:this.options.opacity},{duration:this.options.duration}))},r.prototype.fadeOut=function(){this.options.duration&&this.options.duration>0?this.useVelocity?this.$blurredImage.velocity({opacity:0},{duration:this.options.duration}):this.$blurredImage.animate({opacity:0},{duration:this.options.duration}):this.$blurredImage.css({opacity:0})},r.prototype.generateBlurredImage=function(t){var e=this.$blurredImage;this.internalID=n(),e.length>0&&(this.options.duration&&this.options.duration>0?this.useVelocity?e.first().velocity({opacity:0},{duration:this.options.duration,complete:function(){e.remove()}}):e.first().animate({opacity:0},{duration:this.options.duration,complete:function(){e.remove()}}):e.remove()),i?this.$blurredImage=this.createIMG(t,this.$width,this.$height):this.$blurredImage=this.createSVG(t,this.$width,this.$height)},r.prototype.createOverlay=function(){return this.options.overlayClass&&""!==this.options.overlayClass?t("
").prependTo(this.$element).addClass(this.options.overlayClass):!1},r.prototype.createSVG=function(e,i,n){var r=this,s=o.createElement("svg",{xmlns:o.svgns,version:"1.1",width:i,height:n,id:"blurred"+this.internalID,"class":this.options.imageClass,viewBox:"0 0 "+i+" "+n,preserveAspectRatio:"none"}),a="blur"+this.internalID,u=o.createElement("filter",{id:a}),l=o.createElement("feGaussianBlur",{"in":"SourceGraphic",stdDeviation:this.options.blurAmount}),h=o.createElement("image",{x:0,y:0,width:i,height:n,externalResourcesRequired:"true",href:e,style:"filter:url(#"+a+")",preserveAspectRatio:"none"});h.addEventListener("load",function(){r.$element.trigger("ui.blur.loaded")},!0),h.addEventListener("SVGLoad",function(){r.$element.trigger("ui.blur.loaded")},!0),u.appendChild(l),s.appendChild(u),s.appendChild(h);var d=t(s);return r.options.duration&&r.options.duration>0&&(d.css({opacity:0}),window.setTimeout(function(){"0"===d.css("opacity")&&d.css({opacity:1})},this.options.duration+100)),this.element.insertBefore(s,this.element.firstChild),d},r.prototype.createIMG=function(t,e,i){var n=this,o=this.prependImage(t),r=2*this.options.blurAmount>100?100:2*this.options.blurAmount;return o.css({filter:"progid:DXImageTransform.Microsoft.Blur(pixelradius="+r+") ",top:2.5*-this.options.blurAmount,left:2.5*-this.options.blurAmount,width:e+2.5*this.options.blurAmount,height:i+2.5*this.options.blurAmount}).attr("id","blurred"+this.internalID),o.load(function(){n.$element.trigger("ui.blur.loaded")}),this.options.duration&&this.options.duration>0&&window.setTimeout(function(){"0"===o.css("opacity")&&o.css({opacity:1})},this.options.duration+100),o},r.prototype.prependImage=function(e){var i,n=t('');return i=this.$overlayEl?n.insertBefore(this.$overlayEl).attr("id",this.internalID).addClass(this.options.imageClass):n.prependTo(this.$element).attr("id",this.internalID).addClass(this.options.imageClass)};var s=t.fn.backgroundBlur;t.fn.backgroundBlur=e,t.fn.backgroundBlur.Constructor=r,t.fn.backgroundBlur.noConflict=function(){return t.fn.backgroundBlur=s,this}}(jQuery); -------------------------------------------------------------------------------- /dist/background-blur.js: -------------------------------------------------------------------------------- 1 | /* Image Blur plugin, author @msurguy 2 | 3 | Usage: 4 | 5 | Create a set of elements that follows the following HTML structure: 6 | 7 |
8 |
9 | ... 10 |
11 |
12 | 13 | Add the following css: 14 | 15 | .container { 16 | overflow: hidden; 17 | width: 100%; 18 | position: relative; 19 | } 20 | 21 | .container .bg-blur-overlay { 22 | z-index: -1; 23 | position: absolute; 24 | width: 100%; 25 | height: 100%; 26 | background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSI0NiUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMC4wOCIvPjxzdG9wIG9mZnNldD0iNTklIiBzdG9wLWNvbG9yPSIjMDAwMDAwIiBzdG9wLW9wYWNpdHk9IjAuMDgiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMC45Ii8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); 27 | background-size: 100%; 28 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(46%, rgba(0, 0, 0, 0.08)), color-stop(59%, rgba(0, 0, 0, 0.08)), color-stop(100%, rgba(0, 0, 0, 0.9))); 29 | background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 30 | background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 31 | background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 32 | } 33 | 34 | .container .bg-blur { 35 | z-index: -2; 36 | opacity: 0; 37 | position: absolute; 38 | width: 100%; 39 | min-height: 100%; 40 | height: auto; 41 | display: block; 42 | top: 0; 43 | left: 0; 44 | } 45 | 46 | .container .content { 47 | z-index: 1; 48 | } 49 | 50 | Call the plugin on the container element to add a blurred background to it: 51 | 52 | $('.container').backgroundBlur({ 53 | imageURL : 'http://website.com/images/img.jpg', // URL to the image that will be used for blurring 54 | blurAmount : 10, // Amount of blurrines 55 | imageClass : 'bg-blur', // CSS class that will be applied to the image and to the SVG element, 56 | overlayClass : 'bg-blur-overlay', // CSS class of an element that will overlay the blur background (useful for additional effects) 57 | duration : 1000, // If the image needs to be faded in, how long that should take 58 | endOpacity : 0.6 // Specify the final opacity that the image will have 59 | }); 60 | 61 | Available methods of the plugin are : 62 | 63 | $('.container').backgroundBlur('string'); // swap the image to another image while using initial settings for animation 64 | $('.container').backgroundBlur('fadeIn'); // fade in 65 | $('.container').backgroundBlur('fadeOut'); // fade out 66 | 67 | */ 68 | 69 | ;(function ($) { 70 | 'use strict'; 71 | 72 | // IE version detection 73 | var ie = (function() { 74 | var undef, 75 | v = 3, 76 | div = document.createElement('div'), 77 | all = div.getElementsByTagName('i'); 78 | 79 | while ( 80 | div.innerHTML = '', 81 | all[0] 82 | ){} 83 | 84 | return v > 4 ? v : undef; 85 | 86 | }()); 87 | 88 | // Random ID generator 89 | var randomID = function () { 90 | return '_' + Math.random().toString(36).substr(2, 9); 91 | }; 92 | 93 | //micro lib that creates SVG elements and adds attributes to it 94 | var SVG = { 95 | 96 | //namespaces 97 | svgns: 'http://www.w3.org/2000/svg', 98 | xlink: 'http://www.w3.org/1999/xlink', 99 | 100 | //creating of SVG element 101 | createElement: function(name, attrs) { 102 | var element = document.createElementNS(SVG.svgns, name); 103 | 104 | if (attrs) { 105 | SVG.setAttr(element, attrs); 106 | } 107 | return element; 108 | }, 109 | 110 | //setting attributes 111 | setAttr: function(element, attrs) { 112 | for (var i in attrs) { 113 | if (i === 'href') { //path of an image should be stored as xlink:href attribute 114 | element.setAttributeNS(SVG.xlink, i, attrs[i]); 115 | } else { //other common attribute 116 | element.setAttribute(i, attrs[i]); 117 | } 118 | } 119 | return element; 120 | } 121 | }; 122 | 123 | // backgroundBlur PUBLIC CLASS DEFINITION 124 | // ================================ 125 | 126 | var Blur = function (element, options) { 127 | this.internalID = randomID(); 128 | this.$element = $(element); 129 | this.$width = this.$element.width(); 130 | this.$height = this.$element.height(); 131 | this.element = element; 132 | this.options = $.extend({}, Blur.DEFAULTS, options); 133 | this.$overlayEl = this.createOverlay(); 134 | this.$blurredImage = {}; 135 | this.useVelocity = this.detectVelocity(); // If Velocity.js is present, use it for performant animation 136 | this.attachListeners(); 137 | this.generateBlurredImage(this.options.imageURL); 138 | }; 139 | 140 | Blur.VERSION = '0.1.1'; 141 | 142 | Blur.DEFAULTS = { 143 | imageURL : '', // URL to the image 144 | blurAmount : 10, // Amount of blurrines 145 | imageClass : '', // CSS class that will be applied to the image and to the SVG element, 146 | overlayClass : '', // CSS class of the element that will overlay the blur image 147 | duration : false, // If the image needs to be faded in, how long should that take 148 | opacity : 1 // Specify the final opacity 149 | }; 150 | 151 | Blur.prototype.detectVelocity= function() { 152 | return !!window.jQuery.Velocity; 153 | }; 154 | 155 | Blur.prototype.attachListeners = function() { 156 | this.$element.on('ui.blur.loaded', $.proxy(this.fadeIn, this)); 157 | this.$element.on('ui.blur.unload', $.proxy(this.fadeOut, this)); 158 | }; 159 | 160 | Blur.prototype.fadeIn = function () { 161 | if (this.options.duration && this.options.duration > 0) { 162 | if (this.useVelocity) { 163 | this.$blurredImage 164 | .velocity({ 165 | opacity: this.options.opacity 166 | }, { 167 | duration: this.options.duration 168 | }); 169 | } else { 170 | this.$blurredImage 171 | .animate({ 172 | opacity: this.options.opacity 173 | }, { 174 | duration: this.options.duration 175 | }); 176 | } 177 | 178 | } 179 | }; 180 | 181 | Blur.prototype.fadeOut = function () { 182 | if (this.options.duration && this.options.duration > 0) { 183 | if (this.useVelocity) { 184 | this.$blurredImage 185 | .velocity({ 186 | opacity: 0 187 | }, { 188 | duration: this.options.duration 189 | }); 190 | } else { 191 | this.$blurredImage 192 | .animate({ 193 | opacity: 0 194 | }, { 195 | duration: this.options.duration 196 | }); 197 | } 198 | 199 | } else { 200 | this.$blurredImage.css({'opacity' : 0 }); 201 | } 202 | }; 203 | 204 | Blur.prototype.generateBlurredImage = function (url) { 205 | var $previousImage = this.$blurredImage; 206 | this.internalID = randomID(); 207 | 208 | if( $previousImage.length > 0) { 209 | if (this.options.duration && this.options.duration > 0) { 210 | if (this.useVelocity) { 211 | $previousImage.first().velocity({ opacity: 0 },{ 212 | duration : this.options.duration, 213 | complete : function() { 214 | $previousImage.remove(); 215 | } 216 | }); 217 | } else { 218 | $previousImage.first().animate({ opacity: 0 },{ 219 | duration : this.options.duration, 220 | complete : function() { 221 | $previousImage.remove(); 222 | } 223 | }); 224 | } 225 | } else { 226 | $previousImage.remove(); 227 | } 228 | 229 | } 230 | if (!ie) { 231 | this.$blurredImage = this.createSVG(url, this.$width, this.$height); 232 | } else { 233 | this.$blurredImage = this.createIMG(url, this.$width, this.$height); 234 | } 235 | }; 236 | 237 | Blur.prototype.createOverlay = function () { 238 | if (this.options.overlayClass && this.options.overlayClass !== ''){ 239 | return $('
').prependTo(this.$element).addClass(this.options.overlayClass); 240 | } 241 | 242 | return false; 243 | }; 244 | 245 | Blur.prototype.createSVG = function(url, width, height){ 246 | var that = this; 247 | var svg = SVG.createElement('svg', { //our SVG element 248 | xmlns: SVG.svgns, 249 | version: '1.1', 250 | width: width, 251 | height: height, 252 | id: 'blurred' + this.internalID, 253 | 'class': this.options.imageClass, 254 | viewBox: '0 0 ' + width + ' '+ height, 255 | preserveAspectRatio: 'none' 256 | }); 257 | 258 | var filterId = 'blur' + this.internalID; //id of the filter that is called by image element 259 | var filter = SVG.createElement('filter', { //filter 260 | id: filterId 261 | }); 262 | 263 | var gaussianBlur = SVG.createElement('feGaussianBlur', { // gaussian blur element 264 | 'in': 'SourceGraphic', //"in" is keyword. Opera generates an error if we don't put quotes 265 | stdDeviation: this.options.blurAmount // intensity of blur 266 | }); 267 | 268 | var image = SVG.createElement('image', { //The image that uses the filter of blur 269 | x: 0, 270 | y: 0, 271 | width: width, 272 | height: height, 273 | 'externalResourcesRequired' : 'true', 274 | href: url, 275 | style: 'filter:url(#' + filterId + ')', //filter link 276 | preserveAspectRatio: 'none' 277 | }); 278 | 279 | image.addEventListener('load', function() { 280 | that.$element.trigger('ui.blur.loaded'); 281 | }, true); 282 | 283 | image.addEventListener('SVGLoad', function() { 284 | that.$element.trigger('ui.blur.loaded'); 285 | }, true); 286 | 287 | filter.appendChild(gaussianBlur); //adding the element of blur into the element of filter 288 | svg.appendChild(filter); //adding the filter into the SVG 289 | svg.appendChild(image); //adding an element of an image into the SVG 290 | var $svg = $(svg); 291 | 292 | // Ensure that the image is shown after duration + 100 msec in case the SVG load event didn't fire or took too long 293 | if (that.options.duration && that.options.duration > 0) { 294 | $svg.css({ opacity : 0}); 295 | window.setTimeout(function(){ 296 | if ($svg.css('opacity') === '0') { 297 | $svg.css({ opacity : 1}); 298 | } 299 | }, this.options.duration + 100); 300 | } 301 | this.element.insertBefore(svg, this.element.firstChild); 302 | return $svg; 303 | }; 304 | 305 | Blur.prototype.createIMG = function(url, width, height){ 306 | var that = this; 307 | var $originalImage = this.prependImage(url); 308 | var newBlurAmount = ((this.options.blurAmount * 2) > 100) ? 100 : (this.options.blurAmount * 2); 309 | // apply special CSS attributes to the image to blur it 310 | $originalImage.css({ 311 | //filter property; here the intensity of blur multipied by two is around equal to the intensity in common browsers. 312 | filter: 'progid:DXImageTransform.Microsoft.Blur(pixelradius=' + newBlurAmount + ') ', 313 | //aligning of the blurred image by vertical and horizontal 314 | top: -this.options.blurAmount * 2.5, 315 | left: -this.options.blurAmount * 2.5, 316 | width: width + (this.options.blurAmount * 2.5), 317 | height: height + (this.options.blurAmount * 2.5) }) 318 | .attr('id', 'blurred' + this.internalID); 319 | 320 | $originalImage.load(function(){ 321 | that.$element.trigger('ui.blur.loaded'); 322 | }); 323 | 324 | // Ensure that the image is shown after duration + 100 msec in case the image load event didn't fire or took too long 325 | if (this.options.duration && this.options.duration > 0) { 326 | window.setTimeout(function(){ 327 | if ($originalImage.css('opacity') === '0') { 328 | $originalImage.css({ opacity : 1}); 329 | } 330 | }, this.options.duration + 100); 331 | } 332 | return $originalImage; 333 | }; 334 | 335 | Blur.prototype.prependImage = function(url) { 336 | var $image; 337 | var $imageEl = $(''); 338 | if (this.$overlayEl) { 339 | $image = $imageEl.insertBefore(this.$overlayEl).attr('id', this.internalID).addClass(this.options.imageClass); 340 | } else { 341 | $image = $imageEl.prependTo(this.$element).attr('id', this.internalID).addClass(this.options.imageClass); 342 | } 343 | 344 | return $image; 345 | }; 346 | // backgroundBlur PLUGIN DEFINITION 347 | // ========================== 348 | 349 | function Plugin(option) { 350 | return this.each(function () { 351 | var $this = $(this); 352 | var data = $this.data('plugin.backgroundBlur'); 353 | var options = $.extend({}, Blur.DEFAULTS, $this.data(), typeof option === 'object' && option); 354 | 355 | if (!data) { 356 | $this.data('plugin.backgroundBlur', (data = new Blur(this, options))); 357 | } 358 | if (option === 'fadeIn') { 359 | data.fadeIn(); 360 | } else if (option === 'fadeOut') { 361 | data.fadeOut(); 362 | } else if (typeof option === 'string') { 363 | data.generateBlurredImage(option); 364 | } 365 | }); 366 | } 367 | 368 | var old = $.fn.backgroundBlur; 369 | 370 | $.fn.backgroundBlur = Plugin; 371 | $.fn.backgroundBlur.Constructor = Blur; 372 | 373 | // NO CONFLICT 374 | // ==================== 375 | 376 | $.fn.backgroundBlur.noConflict = function () { 377 | $.fn.backgroundBlur = old; 378 | return this; 379 | }; 380 | 381 | })(jQuery); 382 | -------------------------------------------------------------------------------- /src/background-blur.js: -------------------------------------------------------------------------------- 1 | /* Image Blur plugin, author @msurguy 2 | 3 | Usage: 4 | 5 | Create a set of elements that follows the following HTML structure: 6 | 7 |
8 |
9 | ... 10 |
11 |
12 | 13 | Add the following css: 14 | 15 | .container { 16 | overflow: hidden; 17 | width: 100%; 18 | position: relative; 19 | } 20 | 21 | .container .bg-blur-overlay { 22 | z-index: -1; 23 | position: absolute; 24 | width: 100%; 25 | height: 100%; 26 | background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSI0NiUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMC4wOCIvPjxzdG9wIG9mZnNldD0iNTklIiBzdG9wLWNvbG9yPSIjMDAwMDAwIiBzdG9wLW9wYWNpdHk9IjAuMDgiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMwMDAwMDAiIHN0b3Atb3BhY2l0eT0iMC45Ii8+PC9saW5lYXJHcmFkaWVudD48L2RlZnM+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0idXJsKCNncmFkKSIgLz48L3N2Zz4g'); 27 | background-size: 100%; 28 | background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(46%, rgba(0, 0, 0, 0.08)), color-stop(59%, rgba(0, 0, 0, 0.08)), color-stop(100%, rgba(0, 0, 0, 0.9))); 29 | background-image: -moz-linear-gradient(top, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 30 | background-image: -webkit-linear-gradient(top, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 31 | background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.08) 46%, rgba(0, 0, 0, 0.08) 59%, rgba(0, 0, 0, 0.9) 100%); 32 | } 33 | 34 | .container .bg-blur { 35 | z-index: -2; 36 | opacity: 0; 37 | position: absolute; 38 | width: 100%; 39 | min-height: 100%; 40 | height: auto; 41 | display: block; 42 | top: 0; 43 | left: 0; 44 | } 45 | 46 | .container .content { 47 | z-index: 1; 48 | } 49 | 50 | Call the plugin on the container element to add a blurred background to it: 51 | 52 | $('.container').backgroundBlur({ 53 | imageURL : 'http://website.com/images/img.jpg', // URL to the image that will be used for blurring 54 | blurAmount : 10, // Amount of blurrines 55 | imageClass : 'bg-blur', // CSS class that will be applied to the image and to the SVG element, 56 | overlayClass : 'bg-blur-overlay', // CSS class of an element that will overlay the blur background (useful for additional effects) 57 | duration : 1000, // If the image needs to be faded in, how long that should take 58 | endOpacity : 0.6 // Specify the final opacity that the image will have 59 | }); 60 | 61 | Available methods of the plugin are : 62 | 63 | $('.container').backgroundBlur('string'); // swap the image to another image while using initial settings for animation 64 | $('.container').backgroundBlur('fadeIn'); // fade in 65 | $('.container').backgroundBlur('fadeOut'); // fade out 66 | 67 | */ 68 | 69 | ;(function ($) { 70 | 'use strict'; 71 | 72 | // IE version detection 73 | var ie = (function() { 74 | var undef, 75 | v = 3, 76 | div = document.createElement('div'), 77 | all = div.getElementsByTagName('i'); 78 | 79 | while ( 80 | div.innerHTML = '', 81 | all[0] 82 | ){} 83 | 84 | return v > 4 ? v : undef; 85 | 86 | }()); 87 | 88 | // Random ID generator 89 | var randomID = function () { 90 | return '_' + Math.random().toString(36).substr(2, 9); 91 | }; 92 | 93 | //micro lib that creates SVG elements and adds attributes to it 94 | var SVG = { 95 | 96 | //namespaces 97 | svgns: 'http://www.w3.org/2000/svg', 98 | xlink: 'http://www.w3.org/1999/xlink', 99 | 100 | //creating of SVG element 101 | createElement: function(name, attrs) { 102 | var element = document.createElementNS(SVG.svgns, name); 103 | 104 | if (attrs) { 105 | SVG.setAttr(element, attrs); 106 | } 107 | return element; 108 | }, 109 | 110 | //setting attributes 111 | setAttr: function(element, attrs) { 112 | for (var i in attrs) { 113 | if (i === 'href') { //path of an image should be stored as xlink:href attribute 114 | element.setAttributeNS(SVG.xlink, i, attrs[i]); 115 | } else { //other common attribute 116 | element.setAttribute(i, attrs[i]); 117 | } 118 | } 119 | return element; 120 | } 121 | }; 122 | 123 | // backgroundBlur PUBLIC CLASS DEFINITION 124 | // ================================ 125 | 126 | var Blur = function (element, options) { 127 | this.internalID = randomID(); 128 | this.$element = $(element); 129 | this.$width = this.$element.width(); 130 | this.$height = this.$element.height(); 131 | this.element = element; 132 | this.options = $.extend({}, Blur.DEFAULTS, options); 133 | this.$overlayEl = this.createOverlay(); 134 | this.$blurredImage = {}; 135 | this.useVelocity = this.detectVelocity(); // If Velocity.js is present, use it for performant animation 136 | this.attachListeners(); 137 | this.generateBlurredImage(this.options.imageURL); 138 | }; 139 | 140 | Blur.VERSION = '0.1.1'; 141 | 142 | Blur.DEFAULTS = { 143 | imageURL : '', // URL to the image 144 | blurAmount : 10, // Amount of blurrines 145 | imageClass : '', // CSS class that will be applied to the image and to the SVG element, 146 | overlayClass : '', // CSS class of the element that will overlay the blur image 147 | duration : false, // If the image needs to be faded in, how long should that take 148 | opacity : 1 // Specify the final opacity 149 | }; 150 | 151 | Blur.prototype.detectVelocity= function() { 152 | return !!window.jQuery.Velocity; 153 | }; 154 | 155 | Blur.prototype.attachListeners = function() { 156 | this.$element.on('ui.blur.loaded', $.proxy(this.fadeIn, this)); 157 | this.$element.on('ui.blur.unload', $.proxy(this.fadeOut, this)); 158 | }; 159 | 160 | Blur.prototype.fadeIn = function () { 161 | if (this.options.duration && this.options.duration > 0) { 162 | if (this.useVelocity) { 163 | this.$blurredImage 164 | .velocity({ 165 | opacity: this.options.opacity 166 | }, { 167 | duration: this.options.duration 168 | }); 169 | } else { 170 | this.$blurredImage 171 | .animate({ 172 | opacity: this.options.opacity 173 | }, { 174 | duration: this.options.duration 175 | }); 176 | } 177 | 178 | } 179 | }; 180 | 181 | Blur.prototype.fadeOut = function () { 182 | if (this.options.duration && this.options.duration > 0) { 183 | if (this.useVelocity) { 184 | this.$blurredImage 185 | .velocity({ 186 | opacity: 0 187 | }, { 188 | duration: this.options.duration 189 | }); 190 | } else { 191 | this.$blurredImage 192 | .animate({ 193 | opacity: 0 194 | }, { 195 | duration: this.options.duration 196 | }); 197 | } 198 | 199 | } else { 200 | this.$blurredImage.css({'opacity' : 0 }); 201 | } 202 | }; 203 | 204 | Blur.prototype.generateBlurredImage = function (url) { 205 | var $previousImage = this.$blurredImage; 206 | this.internalID = randomID(); 207 | 208 | if( $previousImage.length > 0) { 209 | if (this.options.duration && this.options.duration > 0) { 210 | if (this.useVelocity) { 211 | $previousImage.first().velocity({ opacity: 0 },{ 212 | duration : this.options.duration, 213 | complete : function() { 214 | $previousImage.remove(); 215 | } 216 | }); 217 | } else { 218 | $previousImage.first().animate({ opacity: 0 },{ 219 | duration : this.options.duration, 220 | complete : function() { 221 | $previousImage.remove(); 222 | } 223 | }); 224 | } 225 | } else { 226 | $previousImage.remove(); 227 | } 228 | 229 | } 230 | if (!ie) { 231 | this.$blurredImage = this.createSVG(url, this.$width, this.$height); 232 | } else { 233 | this.$blurredImage = this.createIMG(url, this.$width, this.$height); 234 | } 235 | }; 236 | 237 | Blur.prototype.createOverlay = function () { 238 | if (this.options.overlayClass && this.options.overlayClass !== ''){ 239 | return $('
').prependTo(this.$element).addClass(this.options.overlayClass); 240 | } 241 | 242 | return false; 243 | }; 244 | 245 | Blur.prototype.createSVG = function(url, width, height){ 246 | var that = this; 247 | var svg = SVG.createElement('svg', { //our SVG element 248 | xmlns: SVG.svgns, 249 | version: '1.1', 250 | width: width, 251 | height: height, 252 | id: 'blurred' + this.internalID, 253 | 'class': this.options.imageClass, 254 | viewBox: '0 0 ' + width + ' '+ height, 255 | preserveAspectRatio: 'none' 256 | }); 257 | 258 | var filterId = 'blur' + this.internalID; //id of the filter that is called by image element 259 | var filter = SVG.createElement('filter', { //filter 260 | id: filterId 261 | }); 262 | 263 | var gaussianBlur = SVG.createElement('feGaussianBlur', { // gaussian blur element 264 | 'in': 'SourceGraphic', //"in" is keyword. Opera generates an error if we don't put quotes 265 | stdDeviation: this.options.blurAmount // intensity of blur 266 | }); 267 | 268 | var image = SVG.createElement('image', { //The image that uses the filter of blur 269 | x: 0, 270 | y: 0, 271 | width: width, 272 | height: height, 273 | 'externalResourcesRequired' : 'true', 274 | href: url, 275 | style: 'filter:url(#' + filterId + ')', //filter link 276 | preserveAspectRatio: 'none' 277 | }); 278 | 279 | image.addEventListener('load', function() { 280 | that.$element.trigger('ui.blur.loaded'); 281 | }, true); 282 | 283 | image.addEventListener('SVGLoad', function() { 284 | that.$element.trigger('ui.blur.loaded'); 285 | }, true); 286 | 287 | filter.appendChild(gaussianBlur); //adding the element of blur into the element of filter 288 | svg.appendChild(filter); //adding the filter into the SVG 289 | svg.appendChild(image); //adding an element of an image into the SVG 290 | var $svg = $(svg); 291 | 292 | // Ensure that the image is shown after duration + 100 msec in case the SVG load event didn't fire or took too long 293 | if (that.options.duration && that.options.duration > 0) { 294 | $svg.css({ opacity : 0}); 295 | window.setTimeout(function(){ 296 | if ($svg.css('opacity') === '0') { 297 | $svg.css({ opacity : 1}); 298 | } 299 | }, this.options.duration + 100); 300 | } 301 | this.element.insertBefore(svg, this.element.firstChild); 302 | return $svg; 303 | }; 304 | 305 | Blur.prototype.createIMG = function(url, width, height){ 306 | var that = this; 307 | var $originalImage = this.prependImage(url); 308 | var newBlurAmount = ((this.options.blurAmount * 2) > 100) ? 100 : (this.options.blurAmount * 2); 309 | // apply special CSS attributes to the image to blur it 310 | $originalImage.css({ 311 | //filter property; here the intensity of blur multipied by two is around equal to the intensity in common browsers. 312 | filter: 'progid:DXImageTransform.Microsoft.Blur(pixelradius=' + newBlurAmount + ') ', 313 | //aligning of the blurred image by vertical and horizontal 314 | top: -this.options.blurAmount * 2.5, 315 | left: -this.options.blurAmount * 2.5, 316 | width: width + (this.options.blurAmount * 2.5), 317 | height: height + (this.options.blurAmount * 2.5) }) 318 | .attr('id', 'blurred' + this.internalID); 319 | 320 | $originalImage.load(function(){ 321 | that.$element.trigger('ui.blur.loaded'); 322 | }); 323 | 324 | // Ensure that the image is shown after duration + 100 msec in case the image load event didn't fire or took too long 325 | if (this.options.duration && this.options.duration > 0) { 326 | window.setTimeout(function(){ 327 | if ($originalImage.css('opacity') === '0') { 328 | $originalImage.css({ opacity : 1}); 329 | } 330 | }, this.options.duration + 100); 331 | } 332 | return $originalImage; 333 | }; 334 | 335 | Blur.prototype.prependImage = function(url) { 336 | var $image; 337 | var $imageEl = $(''); 338 | if (this.$overlayEl) { 339 | $image = $imageEl.insertBefore(this.$overlayEl).attr('id', this.internalID).addClass(this.options.imageClass); 340 | } else { 341 | $image = $imageEl.prependTo(this.$element).attr('id', this.internalID).addClass(this.options.imageClass); 342 | } 343 | 344 | return $image; 345 | }; 346 | // backgroundBlur PLUGIN DEFINITION 347 | // ========================== 348 | 349 | function Plugin(option) { 350 | return this.each(function () { 351 | var $this = $(this); 352 | var data = $this.data('plugin.backgroundBlur'); 353 | var options = $.extend({}, Blur.DEFAULTS, $this.data(), typeof option === 'object' && option); 354 | 355 | if (!data) { 356 | $this.data('plugin.backgroundBlur', (data = new Blur(this, options))); 357 | } 358 | if (option === 'fadeIn') { 359 | data.fadeIn(); 360 | } else if (option === 'fadeOut') { 361 | data.fadeOut(); 362 | } else if (typeof option === 'string') { 363 | data.generateBlurredImage(option); 364 | } 365 | }); 366 | } 367 | 368 | var old = $.fn.backgroundBlur; 369 | 370 | $.fn.backgroundBlur = Plugin; 371 | $.fn.backgroundBlur.Constructor = Blur; 372 | 373 | // NO CONFLICT 374 | // ==================== 375 | 376 | $.fn.backgroundBlur.noConflict = function () { 377 | $.fn.backgroundBlur = old; 378 | return this; 379 | }; 380 | 381 | })(jQuery); 382 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Background Blur - plugin by @msurguy 7 | 8 | 9 | 16 | 17 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | Fork me on GitHub 197 |
198 |
199 |
200 |
201 |
202 |
203 |

Image Blur Plugin

204 |

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

205 | 206 | 207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 | 219 |
220 |
221 |
222 |
223 | 224 | 225 | 226 |
227 | 228 |
229 | 230 | 231 | 232 |
233 | 234 |
235 | 236 | 237 | 238 |
239 | 240 |
241 | 242 | 243 | 244 |
245 |
246 | 247 |
248 |
249 | 252 |
253 |
254 | 255 |
256 |
257 |

Install this plugin with Bower:

258 |
bower install background-blur
259 |

Or manually:

260 |
<script src="jquery.min.js"></script>
261 | <script src="background-blur.min.js"></script>
262 |

Create a container which will contain the blurred image:

263 |
<div id='some-element'></div>
264 |

Then create a blurred image in that container:

265 |
$('#some-element').backgroundBlur({
266 |     imageURL : 'http://URL-of-the-image',
267 |     blurAmount : 50,
268 |     imageClass : 'bg-blur'
269 | });
270 |

OR Create a blurred image and fade it in:

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

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

279 |
// Initialize the blur
280 | $('#some-element').backgroundBlur({
281 |     imageURL : 'http://URL-of-the-image',
282 |     blurAmount : 50,
283 |     imageClass : 'bg-blur'
284 |     duration: 1000, // If the image needs to be faded in, how long that should take
285 |     endOpacity : 1 // Specify the final opacity that the image will have
286 | });
287 | 
288 | //Switch the image
289 | $('#some-element').backgroundBlur('http://URL-of-another-image');
290 |
291 |
292 | 293 |
294 |
295 | 298 |
299 |
300 | 301 |
302 |
303 |

Avatar-based backgrounds (click):

304 |
305 |
306 |
307 | @msurguy 308 |
309 |
310 | @gt 311 |
312 |
313 | @mijustin 314 |
315 |
316 |
317 |
318 |

Code:

319 |
320 | $avatarHolderEl.backgroundBlur({
321 |     imageURL : avatars[0],
322 |     blurAmount : 50,
323 |     imageClass : 'avatar-blur'
324 | });
325 | 
326 | 327 |
328 |
329 |

Tinted overlays:

330 |
331 |
332 | 333 | 334 | 335 | 336 |
337 | 338 | 342 | 343 | 344 |
345 |
346 |
$tintedHolderEl.backgroundBlur({
347 |     imageURL : 'url-of-the-image',
348 |     blurAmount : 10,
349 |     imageClass : 'tinted-bg-blur',
350 |     overlayClass : 'tinted-bg-overlay',
351 |     duration: 1000,
352 |     endOpacity : 1
353 | });
354 |
355 |
356 |
.tinted-bg-blur {
357 |     z-index: -2;
358 |     opacity: 0;
359 |     position: absolute;
360 |     min-height: 100%;
361 |     height: auto;
362 |     display: block;
363 |     top: 0;
364 |     max-height: none;
365 |     /* Add this CSS to remove transparent border around the image */
366 |     left: -10%;
367 |     width: 120%;
368 | }
369 | 
370 | .tinted-bg-overlay {
371 |     z-index: -1;
372 |     position: absolute;
373 |     width: 100%;
374 |     height: 100%;
375 |     background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIxMDAlIiB5Mj0iMTAwJSI+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjZWE0ZmNlIiBzdG9wLW9wYWNpdHk9IjAuOTYiLz4KICAgIDxzdG9wIG9mZnNldD0iNjclIiBzdG9wLWNvbG9yPSIjNmE1ZmMyIiBzdG9wLW9wYWNpdHk9IjAuMTciLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzJiNjdiYyIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
376 |     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+ */
377 |     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+ */
378 |     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+ */
379 |     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+ */
380 |     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+ */
381 |     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 */
382 |     filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5ea4fce', endColorstr='#2b67bc',GradientType=1 ); /* IE6-8 fallback on horizontal gradient */
383 | }
384 |  
385 |
386 |
387 |
388 |
389 |
390 |
391 |

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

392 |
393 |
394 | 395 |
396 | 397 |
398 |
399 |
400 |
401 |
402 | 403 |
404 | 411 |
412 |
413 | 414 | 415 | 416 | 417 |
418 |
419 |
420 |
421 |
422 |
423 | 424 |
425 |
426 |
427 | 430 |
431 |
432 |
433 |
434 |
    435 |
  • Chrome
  • 436 |
  • Firefox
  • 437 |
  • Safari and Safari Mobile (iOS)
  • 438 |
  • 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)
  • 439 |
  • IE9, IE10, IE11
  • 440 |
  • Android browsers
  • 441 |
  • Possibly, more. Please let me know if some browser doesn't work
  • 442 |
443 |
444 |
445 | 446 |
447 |
448 | 451 |
452 |
453 |
454 |
455 |

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

456 |

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.

457 |
458 |
459 | 460 |
461 |
462 | 465 |
466 |
467 |
468 |
469 |

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

470 |
471 |
472 | 473 |
474 |
475 | 478 |
479 |
480 |
481 |
482 |

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

483 |
484 |
485 | 486 |
487 | 488 | 489 | 490 | 491 | 492 | 493 | 595 | 596 | 597 | 598 | --------------------------------------------------------------------------------