javascript中的SVG转换在IE 11中不起作用

SVG translate transform in javascript not working in IE 11

本文关键字:不起作用 IE 中的 SVG 转换 javascript      更新时间:2023-09-26

以下代码在IE 11中不起作用(Chrome运行良好)

<html>
    <head>
        <script>
            window.onload = function() {document.getElementById("abc").style.transform = "translate(100px,100px)";};
    </script>
</head>
<body>
    <div>   
        <svg width="200" height="200">
            <g id="abc">
                <polygon points="14,7 0,14 0,0"></polygon>
            </g>
        </svg>
    </div>
</body>

对于IE,您需要将transform设置为属性,而不是CSS样式。

请注意,对于属性,不允许使用单位。

<html>
    <head>
        <script>
            window.onload = function() {document.getElementById("abc").setAttribute("transform", "translate(100, 100)")};
    </script>
</head>
<body>
    <div>   
        <svg width="200" height="200">
            <g id="abc">
                <polygon points="14,7 0,14 0,0"></polygon>
            </g>
        </svg>
    </div>
</body>