小编mor*_*alc的帖子

在SVG中包含JavaScript

我试图通过在JavaScript中嵌入JavaScript来使用JavaScript创建交互式SVG代码.我不知道这是否是正确的方法:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1"
xmlns="http://www.w3.org/2000/svg"
onkeypress="move()">
<script type="text/javascript">
    <![CDATA[
    var x;
    var y;
    function move()
    {
        x = new Number(svg.getElementsByTagName("circle")[0].getAttribute("cx"));
        y = new Number (svg.getElementsByTagName("circle")[0].getAttribute("cy"));
        switch (event.keyCode)
        {
            case 119:
            y--;
            y = y.toString();
            svg.getElementsByTagName("circle").setAttribute("cy",y);
            break;
            case 115:
            y++;
            y = y.toString();
            svg.getElementsByTagName("circle").setAttribute("cy",y);
            break;
            case 97:
            x--;
            x = x.toString();
            svg.getElementsByTagName("circle").setAttribute("cx",x);
            break;
            case 100:
            x++;
            x = x.toString();
            svg.getElementsByTagName("circle").setAttribute("cx",x);
            break;
            default:
        }
    }
    ]]>
</script>
<rect x="0" y="0" …
Run Code Online (Sandbox Code Playgroud)

javascript svg interactive

29
推荐指数
1
解决办法
5万
查看次数

两个SVG元素触摸时的事件

SVG中是否可以使用任何方法调用偶数两个特定元素?或者我是否需要编写很长的代码,并弄清楚它们的边界是否与复杂的数学接触?

javascript svg dom intersection

11
推荐指数
1
解决办法
5966
查看次数

标签 统计

javascript ×2

svg ×2

dom ×1

interactive ×1

intersection ×1