1

我正在构建一个 SVG 地图动画。到目前为止一切都很好,动画不仅仅是好的,但我在 IE 上的 SVG 解释有问题。路径上的悬停以一种奇怪的方式触发(我认为这是在边界框上触发的),所以当所有地图都到位时,有一些路径被完全包围并且无法触摸。

我只放置了 SVG 的一部分,所以你可以知道我在说什么:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg 
    xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink"  
    width="69.279999"
    height="105.34"
    viewBox="0 0 230.93362 351.1338">
  <style
     id="style3001">path { fill : blue } path:hover { fill : green }</style>
  <g
     transform="matrix(111.33376,0,0,116.46504,-16701.937,-16253.569)"
     id="g3003">
    <path       
       d="m 150.758,142.099 c -0.0517,0.0423 -0.10333,0.0847 -0.155,0.127 -0.0323,-0.0115 -0.0717,-0.0136 -0.0999,-0.0307 -0.024,-0.0436 -0.0573,-0.0849 -0.0756,-0.12979 0.009,-0.0523 0.003,-0.10875 0.0208,-0.15836 0.0344,-0.0743 0.0761,-0.14613 0.10581,-0.22198 0.005,-0.0414 0.0282,-0.0843 0.004,-0.12357 -0.0307,-0.0869 -0.0614,-0.17373 -0.0921,-0.2606 0.0173,-0.067 0.0347,-0.134 0.052,-0.201 -0.0558,-0.0445 -0.11683,-0.0847 -0.16951,-0.13191 -0.0118,-0.0328 -0.0427,-0.0635 -0.0418,-0.0978 0.0191,-0.0675 0.0299,-0.13837 0.054,-0.20374 0.0808,-0.13386 0.16153,-0.26771 0.2423,-0.40156 -0.0333,-0.0593 -0.0667,-0.11867 -0.1,-0.178 0.0429,-0.0125 0.0967,-0.004 0.12461,-0.045 0.0491,-0.048 0.0983,-0.096 0.14739,-0.14402 0.10933,0.15967 0.21867,0.31933 0.328,0.479 0.0641,0.0366 0.12439,0.0825 0.19078,0.11335 0.0454,0.01 0.0908,0.0198 0.13622,0.0297 0.0407,0.097 0.0813,0.194 0.122,0.291 -0.0197,0.10233 -0.0393,0.20467 -0.059,0.307 0.0963,0.072 0.19267,0.144 0.289,0.216 -0.0939,0.1481 -0.18414,0.29937 -0.28027,0.44549 -0.0662,0.0542 -0.13249,0.10834 -0.19873,0.16251 -0.0375,-0.003 -0.0637,-0.0198 -0.0742,-0.0569 -0.0264,-0.0418 -0.0373,-0.0973 -0.0859,-0.11945 -0.0274,-0.0195 -0.053,-0.0458 -0.0893,-0.0325 -0.0908,0.008 -0.18169,0.0152 -0.27253,0.0228 -0.0281,0.0458 -0.0638,0.0891 -0.0873,0.13651 -0.0128,0.0393 0.008,0.0627 0.0419,0.08 0.0366,0.0157 0.0475,0.0416 0.0314,0.0783 -0.003,0.0161 -0.006,0.0321 -0.009,0.0482 z"
    />
    </g>
</svg>

指针事件对此没有影响。

欢迎任何帮助或建议。提前致谢。

4

2 回答 2

2

这似乎是 IE 中的一个错误。它似乎与边界框无关,因为您可以在不触发翻转的情况下侵入 bbox 的某些位置。

起初我怀疑它可能使用贝塞尔控制点作为边界多边形,但是当我将所有曲线转换为线时,它仍然在发生。

然后我怀疑它可能与变换有关,所以我创建了以下 SVG 来测试这个理论:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100">
  <style id="style3001">path { fill : blue; stroke-width: 0 } path:hover { fill : green }</style>
  <g>
    <path d="m 50,0 c 25,0 50,25 50,50 l 0,50 l -50,-25 l -50,25 l 0,-100 z" />
  </g>
</svg>

瞧!它按预期工作。

因此,如果您更改您的 SVG 以删除转换并预乘您的坐标,您应该会发现它在 IE 中可以正常工作。希望您自己生成 SVG,这样会很容易。:)

于 2013-06-10T02:54:23.860 回答
1

通过http://jsfiddle.net/3591mj2o/18/,似乎没有必要删除转换代码来解决这个 IE 问题。只要坐标值足够大(根据我的经验,大于 1),鼠标悬停就会正确运行。

当然,为了使 SVG 不会因为这种解决方法而改变大小,比例需要除以坐标乘以的相同因子。

<!--IE Bug SVG-->
<svg height="200" width="150">
    <path id="path2" transform="translate(0,0)scale(1000)" d="M0.075 0 L0 0.2 L0.15 0.2 Z" />
</svg>

<!--Working SVG with scale and transform -->
<svg height="200" width="150">
    <path id="path1" transform="translate(0,0)scale(10)" d="M7.5 0 L0 20 L15 20 Z" />
</svg>
于 2015-02-10T15:41:12.150 回答