SVG Mask Transparent Circle - show only text without yellow background

Hello I am new to svg masks and I have the following problem:

The circle is an svg mask that follows the cursor over the image. Behind the image is another image with tagcloud, which is a png with a transparent background.

Now I just want to see the text from the image behind WITHOUT the yellow background from the website. Is it possible? I would be very glad if someone could help me.

Here is my code from the demo:

https://jsfiddle.net/ayyuqrw4/1/

    <svg>
        <defs>
            <mask id="cursorMask" maskUnits="objectBoundingBox" maskContentUtils="objectBoundingBox">
                <g>
                    <rect x="0" y="0" width="1600" height="700" fill="#FFFFFF" />
                    <circle cx="0" cy="0" r="60" stroke="black" stroke-width="0" fill="black" fill-opacity="1" />
                </g>
            </mask>
        </defs>
        <image width="1600" height="700" xlink:href="https://41.media.tumblr.com/e91c999c320c29a28053c6a933da1e81/tumblr_mkjnibe1xH1s9yt1no1_500.png" />
        <image width="1600" height="700" xlink:href="http://www.liftopia.com/media/product/275/102102_Ski-Banff-Lake-Louise-Sunshine-1-Day-Lift-Tickets.jpg" />
    </svg>

var img = document.getElementsByTagName("image")[1];
var imgPos = img.getBoundingClientRect();
var imgX = imgPos.left;
var imgY = imgPos.top;
var rect = document.getElementsByTagName("circle")[0];
var rectHalfWidth = rect.getAttribute("width") / 2;
var rectHalfHeight = rect.getAttribute("height") / 2;
img.addEventListener("mousemove", function (e) {
    rect.setAttribute("cx", e.clientX - imgX - rectHalfWidth);
    rect.setAttribute("cy", e.clientY - imgY - rectHalfHeight);
}, false);

body {
    background-color: yellow;
}

svg {
    width: 1600px;
    height: 700px;
}
image:hover {
    mask: url("#cursorMask");
}

      

And this is what I want:

Final result

+3


source to share


1 answer


Paste the original image for everything.

Note how I adjusted your getElementsByTagName to match because I am lazy, but it would be better if you give the image you want to select the id and convert to getElementById.



var img = document.getElementsByTagName("image")[2];
var imgPos = img.getBoundingClientRect();
var imgX = imgPos.left;
var imgY = imgPos.top;
var rect = document.getElementsByTagName("circle")[0];
var rectHalfWidth = rect.getAttribute("width") / 2;
var rectHalfHeight = rect.getAttribute("height") / 2;
img.addEventListener("mousemove", function (e) {
    rect.setAttribute("cx", e.clientX - imgX - rectHalfWidth);
    rect.setAttribute("cy", e.clientY - imgY - rectHalfHeight);
}, false);
      

body {
    background-color: yellow;
}

svg {
    width: 1600px;
    height: 700px;
}
image:hover {
    mask: url("#cursorMask");
}
      

    <svg>
        <defs>
            <mask id="cursorMask" maskUnits="objectBoundingBox" maskContentUtils="objectBoundingBox">
                <g>
                    <rect x="0" y="0" width="1600" height="700" fill="#FFFFFF" />
                    <circle cx="0" cy="0" r="60" stroke="black" stroke-width="0" fill="black" fill-opacity="1" />
                </g>
            </mask>
        </defs>
        <image width="1600" height="700" xlink:href="http://www.liftopia.com/media/product/275/102102_Ski-Banff-Lake-Louise-Sunshine-1-Day-Lift-Tickets.jpg" />
        <image width="1600" height="700" xlink:href="https://41.media.tumblr.com/e91c999c320c29a28053c6a933da1e81/tumblr_mkjnibe1xH1s9yt1no1_500.png" />
        <image width="1600" height="700" xlink:href="http://www.liftopia.com/media/product/275/102102_Ski-Banff-Lake-Louise-Sunshine-1-Day-Lift-Tickets.jpg" />
    </svg>
      

Run code


+1


source







All Articles