Skip to content

Instantly share code, notes, and snippets.

@badabingbreda
Last active February 3, 2022 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save badabingbreda/9ba7b8ab8e18c0d2fbbcac51cc30971a to your computer and use it in GitHub Desktop.
Save badabingbreda/9ba7b8ab8e18c0d2fbbcac51cc30971a to your computer and use it in GitHub Desktop.
Snippet of code to change the row background-image to a blurred out version (or other filter effect)
// rowblur.js for Beaver Builder rows
// (c) 2018 Didou Schol / BadabingBreda
// rowblur.js may be freely distributed under the MIT license.
//
// add 'blureffect' as a class to the row and set the background-type to 'image'
// copy the code below into the "Global Settings > Javascript" tab and the rest will follow
// blur effect is hidden on fl_builder page, and needs a reload after page is saved.
// When normally browsing the site loads normally.
(function($) {
function getCSSProps( element , props ) {
let $this = $(element);
var values = {};
for (let i = 0; i < props.length ; i++) {
values[props[i]] = $this.css( props[i]);
}
return values;
}
$('document').ready( function() {
// perform code only when not in editor
if (!/[?&]fl_builder/.test(location.search)) {
var blurRows = $('.fl-row-bg-photo.blureffect');
for (let i = 0; i < blurRows.length; i++ ) {
// current wrap
let $currentWrap = $( blurRows[i] ).find('.fl-row-content-wrap');
// get the properties
let cssProps = getCSSProps( $currentWrap , ['background-image', 'background-repeat', 'background-position', 'background-attachment', 'background-size']);
// add an element after the content-wrap
$( blurRows[i] ).css({ position: 'relative', overflow: 'hidden' }).append('<div class="blurtainer"></div>')
// change the current wrap, hide it's image and set the z-index
$currentWrap.css({backgroundImage: 'none', zIndex: 1});
// clone the properties of the original wrap and join them with some new ones, make sure to set z-index to one less than original wrap
$( blurRows[i] ).find('.blurtainer').css( Object.assign(cssProps,{filter: 'blur(5px)', position: 'absolute', zIndex: '0', top:'-5%', left: '-5%',width: '110%', height: '110%'}) );
}
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment