Search code examples
javascriptsvgnestedmouseoversmil

SVG mouseover does not work on nested elements


I would like to make it so that when you hover over a nested group #sec7kpi-c and then further into the text inside the animation effect when you mouseover continues.

<g transform="matrix(1 0 0 1 150 150)" id="sec7kpi">
  <g transform="matrix(1 0 0 1 0 0)" id="sec7kpi-c">
    <ellipse fill="#372356" stroke="#27AE60" stroke-width="16" stroke-miterlimit="10" cx="0" cy="0" rx="71" ry="71" />
    <text id="sec7text" x="-33" y="15" fill="#27AE60" font-family="LatoRegular" font-size="38.8363">KPI</text>  
  </g>
</g>
<animateTransform attributeType="XML"
                  xlink:href="#sec7kpi-c"
                  attributeName="transform"
                  type="scale"
                  dur="1s"
                  from="1"
                  to="2"
                  restart="whenNotActive"
                  begin="mouseover"
                  calcMode="spline"
                  values="1;1.5;1"  
                  keyTimes="0;0.5;1"
                  keySplines=".16,.59,.46,.98;.88,.27,.37,1.52"
                  fill="freeze"                     
                  id="c-hover">
</animateTransform>

Solution

  • You can set the text pointer-events property to none to avoid this.

    Note that your keySplines values are invalid (they must all be <= 1) so your animation should not work as written (if it does you should raise a bug on that UA). I've corrected that in my version.

    Also I've removed the from and to attributes as they are ignored if you provide a values attribute.

    body, html {
      width: 100%;
      height: 100%;
    }
    <svg width="100%" height="100%">
      <g transform="matrix(1 0 0 1 150 150)" id="sec7kpi">
        <g transform="matrix(1 0 0 1 0 0)" id="sec7kpi-c">
          <ellipse fill="#372356" stroke="#27AE60" stroke-width="16" stroke-miterlimit="10" cx="0" cy="0" rx="71" ry="71" />
          <text id="sec7text" x="-33" y="15" fill="#27AE60" font-family="LatoRegular" font-size="38.8363" pointer-events="none">KPI</text>  
        </g>
      </g>
      <animateTransform attributeType="XML"
                        xlink:href="#sec7kpi-c"   
                        attributeName="transform"
                        type="scale"
                        dur="1s"
                        restart="whenNotActive"
                        begin="mouseover"
                        calcMode="spline"
                        values="1;1.5;1" 
                        keyTimes="0;0.5;1"
                        keySplines=".16,.59,.46,.98;.88,.27,.37,1"
                        fill="freeze"                        
                        id="c-hover">
      </animateTransform> 
    </svg>