svg-mask
svg-mask
by hangyangws
HTML
<svg class="svg-mask">
<defs>
<mask id="mask" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
<linearGradient id="grad" gradientUnits="objectBoundingBox" x2="0" y2="1">
<stop stop-color="white" offset="0" />
<stop stop-color="green" stop-opacity="0" offset="1" />
</linearGradient>
<circle cx="0.50" cy="0.50" r="0.50" id="circle" fill="url(#grad)" />
</mask>
</defs>
</svg>
<svg class="masked-element" width="300" height="300" viewBox="0 0 300 300">
<image
width="300px" height="300px"
xlink:href="http://www.abbeyjfitzgerald.com/wp-content/uploads/2016/07/forest-example-square.jpg"
/>
</svg>
CSS
.svg-mask {
position: absolute;
width: 0;
height: 0;
overflow: hidden;
}
.masked-element image {
mask: url(#mask);
}