SVG translate transform in javascript not working in IE 11

我与影子孤独终老i 提交于 2019-12-13 07:21:24

问题


The following code doesn't work in IE 11 (Chrome works fine)

<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>


回答1:


For IE you need to set transform as an attribute rather than as a CSS style.

Note that for an attribute, units are not allowed.

<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>


来源:https://stackoverflow.com/questions/37109349/svg-translate-transform-in-javascript-not-working-in-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!