问题
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