Two instances of blur.js possible?

自闭症网瘾萝莉.ら 提交于 2019-12-08 07:49:05

问题


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.


回答1:


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);



回答2:


This fork of Blur.js by CezaryDanielNowak fixes the limitation imposed by the initial implementation and allows for multi-element blurring simultaneously - no need for setTimeout.



来源:https://stackoverflow.com/questions/21025702/two-instances-of-blur-js-possible

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!