Seán Hayes
Seán Hayes

Reputation: 4360

SVG mask always turns element invisible

I'm using Chrome 49.0.2623.87 (64-bit) on Ubuntu 15.10. Doesn't work in Firefox either.

I have the following code using svg.js:

function blockmouseenterHandler(){
    console.debug('mouseenter')
    var mask = anatomy.frame.rect(100,100).move(0,0).addClass('hovermask').fill({ color: '#000'});
    this.maskWith(mask);
}

The mask/defs it creates:

<defs id="SvgjsDefs1000">
    <clipPath id="SvgjsClipPath1022">
        <rect id="SvgjsRect1023" width="685.528361111111" height="692.5839166666665" x="0" y="0"></rect>
    </clipPath>
    <clipPath id="SvgjsClipPath1040">
        <rect id="SvgjsRect1041" width="1452.812972222222" height="128.13947222222222" x="0" y="0"></rect>
    </clipPath>
    <clipPath id="SvgjsClipPath1057">
        <rect id="SvgjsRect1058" width="1071.834138888889" height="128.13947222222225" x="0" y="0"></rect>
    </clipPath>
    <mask id="SvgjsMask1062">
        <rect id="SvgjsRect1061" width="100" height="100" x="0" y="0" class="hovermask" fill="#000000"></rect>
    </mask>
</defs>

The masked element:

<g id="SvgjsG1027" transform="matrix(1,0,0,1,810.1224365234375,191.731201171875)" class="block" clip-path="url(&quot;#SvgjsClipPath1040&quot;)" mask="url(&quot;#SvgjsMask1062&quot;)">
    <rect id="SvgjsRect1028" width="1452.812972222222" height="128.13947222222222" x="0" y="0" fill="#dddddd" stroke-width="0" opacity="0.5"></rect>
    <g id="SvgjsG1029" transform="matrix(1,0,0,1,0,0)">
        <rect id="SvgjsRect1030" width="1452.81298828125" height="128.13946533203125" class="svg_select_boundingRect svg_select_points"></rect>
        <circle id="SvgjsCircle1031" r="3.5" cx="0" cy="0" class="svg_select_points_lt svg_select_points"></circle>
        <circle id="SvgjsCircle1032" r="3.5" cx="1452.81298828125" cy="0" class="svg_select_points_rt svg_select_points"></circle>
        <circle id="SvgjsCircle1033" r="3.5" cx="1452.81298828125" cy="128.13946533203125" class="svg_select_points_rb svg_select_points"></circle>
        <circle id="SvgjsCircle1034" r="3.5" cx="0" cy="128.13946533203125" class="svg_select_points_lb svg_select_points"></circle>
        <circle id="SvgjsCircle1035" r="3.5" cx="726.406494140625" cy="0" class="svg_select_points_t svg_select_points"></circle>
        <circle id="SvgjsCircle1036" r="3.5" cx="1452.81298828125" cy="64.06973266601562" class="svg_select_points_r svg_select_points"></circle>
        <circle id="SvgjsCircle1037" r="3.5" cx="726.406494140625" cy="128.13946533203125" class="svg_select_points_b svg_select_points"></circle>
        <circle id="SvgjsCircle1038" r="3.5" cx="0" cy="64.06973266601562" class="svg_select_points_l svg_select_points"></circle>
        <circle id="SvgjsCircle1039" r="3.5" cx="726.406494140625" cy="20" class="svg_select_points_rot"></circle>
    </g>
    <text id="SvgjsText1042" font-family="Ubuntu" font-size="120" text-anchor="middle" fill="#000000" alignment-baseline="central" width="1452.812972222222" height="128.13947222222222" x="726.406486111111" y="-35.00838888888889" svgjs:data="{&quot;leading&quot;:&quot;1.2em&quot;}">
        <tspan id="SvgjsTspan1043" dy="144" x="726.406486111111" svgjs:data="{&quot;newLined&quot;:true}">Book Title</tspan>
    </text>
</g>

No matter what fill color I use on the mask, it always turns the masked element completely invisible. From what I understand, only a color of #fff should make it completely transparent, #000 should not mask at all, and values in between should give partial transparency, correct?

Update: https://jsfiddle.net/cmuyebma/

Upvotes: 0

Views: 680

Answers (1)

Paul LeBeau
Paul LeBeau

Reputation: 101820

Your mask consists of a 100x100 black rectangle. Black in a mask represents transparent.

So you are masking your target element with a mask that represents transparent. So it becomes invisible.

If you want a 100x100 section of your target element to be visible, then you should make the mask rectangle white.

If you want a 100x100 hole in your target element, then you should have a completely white mask with a 100x100 black rectangle on top (representing the hole).

Upvotes: 1

Related Questions