Search code examples
jqueryblurry

Two instances of blur.js possible?


I would like to use blur.js on two different elements with different sources. How can I achieve that?

My code so far:

 $('.blurry1').blurjs({
      source: '.source1',
      cache: false, 
      radius: 10,
      debug: 1,
 });

 $('.blurry2').blurjs({
      source: '.source2',
      cache: false, 
      radius: 10,
      debug: 1,
 });

Only the second function is executed correctly.


Solution

  • It can be done but it’s a bit of a hack as it relies on the setTimeout function to wait until the first blurjs function has finished.

    $('#blurry1').blurjs({
        source: 'body',
        radius: 30,
        overlay: 'rgba(0, 0, 0, .2)',
        cache: false
    });
    
    setTimeout(function() {
        $('#blurry2').blurjs({
            source: '#bg2',
            radius: 30,
            overlay: 'rgba(0, 0, 0, .2)',
            cache: false
        });
    }, 1000);