简体   繁体   English

蒙版框仍会调用功能

[英]Masked boxes still call functions

There's a way to attach a event like mouse over into a mask? 有没有一种方法可以将鼠标悬停在遮罩上? This example shows my problem: http://goo.gl/DRhsH 此示例显示了我的问题: http : //goo.gl/DRhsH

When you pass the mouse NEXT to the blue box, it changes the color from the mask, what i would like to do is to just call that event WHEN the mouse pass over blue box (Not near - This happen beucause the blue and red boxes are masked with another rect, and when you pass the mouse near them) , because i need to work with only the displayed image, and binding a event like that should solve my problem. 当您将鼠标移至下一个蓝色框时,它会更改蒙版的颜色,我想做的只是在鼠标移过蓝色框时调用该事件(不近-这是因为蓝色和红色框被另一个矩形遮罩,并且当您将鼠标传递到它们附近时,因为我只需要处理显示的图像,并且绑定这样的事件应该可以解决我的问题。

i tried to bind the click/mouseover into a group but it keeps the same result, the whole image is acessible, and not just the part viewed. 我试图将click / mouseover绑定到一个组中,但结果保持不变,整个图像都是可访问的,而不仅仅是查看的部分。 I also tried to clip it, but it keep tracking the content clipped 我也尝试剪辑它,但它会继续跟踪剪辑的内容

Edit : Replaced the previous answer as did things improperly and bonsaijs apparently won't allow clipping. 编辑 :替换了以前的答案,因为事情做得不正确,并且bonsaijs显然不允许剪切。

I'd suggest using the mask path as a clip path as well, but bonsiajs doesn't seem to support that. 我建议也将mask路径用作剪切路径,但是bonsiajs似乎不支持该路径。 Anyway, here's an SVG structure that triggers events as you intended. 无论如何,这是一个SVG结构,可按您的预期触发事件。 If this can't be generated using bonsaijs, maybe you can do it in another way. 如果无法使用bonsaijs生成此代码,则可以用另一种方式来实现。

<svg width="596" height="596" viewBox="-0.5 -0.5 596 596" 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink">
  <defs>
    <mask id="mask">
      <path d="M 0 0 l 50 0 l 0 150 l -50 0 Z" fill="rgba(255,255,0,1)"
        transform="matrix(1,0,0,1,80,0)" id="maskPath"/>
    </mask>
    <clipPath id="clipPath">
      <use xlink:href="#maskPath"/>
    </clipPath>
  </defs>
  <g>
    <g mask="url(#mask)" clip-path="url(#clipPath)" onmouseover="alert('in')">
      <path d="M 0 0 l 100 0 l 0 100 l -100 0 Z" fill="rgba(255,0,0,1)"/>
      <path d="M 0 0 l 100 0 l 0 100 l -100 0 Z" fill="rgba(0,0,255,1)"
        transform="matrix(1,0,0,1,50,50)"/>
    </g>
  </g>
</svg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM