Adrián Pérez
Adrián Pérez

Reputation: 107

Snap.svg: Masking image in path makes a weird opacity and filter effect

I have this fiddle with the issue, I'm trying to achieve a normal mask for each path in order to animate after with Snap, the problem is that when I apply the mask the image becames B&W and reduces it's opacity.

https://jsfiddle.net/adrianperez/agevu82g/1/

I have asked at the snap.js Google group but no answers at the moment, any clue that what I'm doing wrong?

var s = new Snap('.brushes'),
allPaths = s.selectAll("path");

allPaths.forEach(function(el) {
el.attr({
  fillOpacity: 0
 });
});


for(i = 0; i < allPaths.length; i++){
var thisPath = allPaths[i],
    img = s.image('http://cf067b.medialib.glogster.com/media/60/607ef3f3255bd2db1e2444562b7468b595e287b42a1ea594ec8a98d30f7ce9f5/cute-kitten.jpg', 0, 0, 454, 322);

img.attr({
fill: 'white'
});

thisPath.attr({
mask:img
});
thisPath.animate({fillOpacity: 1}, 200);

}
s.append(allPaths);

Upvotes: 0

Views: 1285

Answers (1)

Adri&#225;n P&#233;rez
Adri&#225;n P&#233;rez

Reputation: 107

Ok! It's solved, here it is the fiddle working

https://jsfiddle.net/agevu82g/8/

var s = new Snap('.brushes'),
allPaths = s.selectAll("g");

allPaths.forEach(function(el) {
el.attr({
    fillOpacity: 0,
    fill: 'white'
});
});


allPaths.forEach( function(el, i ) {
var img =   s.image('http://cf067b.medialib.glogster.com/media/60/607ef3f3255bd2db1e2444562b7468b595e287b42a1ea594ec8a98d30f7ce9f5/cute-kitten.jpg', 0, 0, 454, 322);

img.attr({ mask: el });

setTimeout( function() {
    el.animate({fillOpacity: 1}, 2000);
}, i * 1000);


});

Upvotes: 1

Related Questions