Reputation: 540
I've tried to mask image with my png and it perfectly works on chrome. However, it doens't work on Firefox. Here is the style I used
-webkit-mask: url("../img/mask.png");
-o-mask: url("../img/mask.png");
-ms-mask: url("../img/mask.png");
Does Firefox support masking and how to do it?
Upvotes: 1
Views: 5396
Reputation: 499
The best idea is to use png as a main image and use it as a frame Example:
<img src="mask.png" alt="PNG which will mask" id="maskedImage"/>
#maskedImage { background:url(your_image_for_masking.jpg); }
You can use JS for masking all images on your page:
var png_overlay = 'mask.png'
function pngFrame() {
var imgs = document.images;
for( var i = 0, img; img = imgs[i]; i++ ) {
if( img.className.indexOf('frame') >= 0 ) {
var bgSrc = img.src;
img.style.background = "url(" + bgSrc + ")";
img.src = png_overlay;
}
}
}
If You can't use JS You can use SVG masking like this:
<svg>
<defs>
<mask maskContentUnits="objectBoundingBox" maskUnits="objectBoundingBox" id="masking">
<circle fill="white" r=".35" cy=".5" cx=".5"/>
</mask>
</defs>
</svg>
svg inside html
mask:url(#masking)
svg outside html
mask: url("svg.svg#maskid");
Upvotes: 3