javascript - 鼠标悬停时 SVG 比例 - 元素消失

标签 javascript xml svg

我制作了一张 SVG map ,我希望它在鼠标悬停时改变颜色并增加尺寸。我设法让颜色更改正常工作,但当我尝试缩放元素时,当我将鼠标悬停在它上面时,它完全消失了!

<g
   style="fill:#999999"
   id="newzealand"
   onmouseover="this.setAttribute('transform', 'scale(2)');this.style.fill='#83b901';document.getElementById('countryText').textContent='New Zealand';"
   onmouseout="this.style.fill='#999';document.getElementById('countryText').textContent='';"
   >
  <path
     inkscape:connector-curvature="0"
     id="path3034"
     d="m 645,409.28571 -5,7.85715 -3.57143,2.85714 -2.5,5.71429 5.71429,1.42857 3.21428,-6.42857 0,-1.78572 2.14286,-0.71428 3.57143,-7.85715 z"
     style="stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
  <path
     inkscape:connector-curvature="0"
     id="path3036"
     d="M 650.35714,411.07143 650,407.85714 l -1.78571,-2.14285 0.71428,-4.28572 -2.5,-6.78571 0,-1.42857 2.14286,2.85714 2.14286,2.5 2.85714,3.92857 2.14286,-1.78571 0,3.21428 -1.78572,2.14286 z"
     style="stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>

我也尝试使用动画元素,但得到了相同的结果。它似乎与平移和旋转配合得很好。

最佳答案

您的绘图不在原点,因此当您缩放它时,它会从页面边缘消失。 m 645,409 实际上变为 m 1290,818。如果我们删除坐标的加倍,绘图将保持在同一点。

<g
   style="fill:#999999"
   id="newzealand"
   onmouseover="this.setAttribute('transform', 'translate(-645, -409) scale(2)');this.style.fill='#83b901';document.getElementById('countryText').textContent='New Zealand';"
   onmouseout="this.style.fill='#999';document.getElementById('countryText').textContent='';"
   >
  <path
     id="path3034"
     d="m 645,409.28571 -5,7.85715 -3.57143,2.85714 -2.5,5.71429 5.71429,1.42857 3.21428,-6.42857 0,-1.78572 2.14286,-0.71428 3.57143,-7.85715 z"
     style="stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
  <path
     id="path3036"
     d="M 650.35714,411.07143 650,407.85714 l -1.78571,-2.14285 0.71428,-4.28572 -2.5,-6.78571 0,-1.42857 2.14286,2.85714 2.14286,2.5 2.85714,3.92857 2.14286,-1.78571 0,3.21428 -1.78572,2.14286 z"
     style="stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
</g>

关于javascript - 鼠标悬停时 SVG 比例 - 元素消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10756423/

相关文章:

java - 使用 Spring :message to define form tag attribute in Spring web application

d3.js - dc.js geochoropleth map 缩放

javascript - 为什么将 var 与 "text"进行比较不起作用?

javascript - 使用二进制值混淆 javascript 代码?

java - 如何从 XML 元素生成 XSD

javascript - 创建第二个 SVG 后,D3.js 不在第一个 SVG 上显示标签

html - 包含透明 SVG 的 img 元素的背景颜色不会在 iOS 浏览器中显示

javascript - sqlite输出变量到js中

javascript - jQuery - 未捕获范围错误 : Maximum call stack size exceeded

html - 在 XSLT 中生成指向按字母顺序排列的文档部分的快捷链接