javascript 中的 SVG 转换转换在 IE 11 中不起作用 [英] SVG translate transform in javascript not working in IE 11

查看:36
本文介绍了javascript 中的 SVG 转换转换在 IE 11 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在 IE 11 中不起作用(Chrome 工作正常)

<头><脚本>window.onload = function() {document.getElementById("abc").style.transform = "translate(100px,100px)";};<身体><div><svg width="200" height="200"><g id="abc"><polygon points="14,7 0,14 0,0"></polygon></svg>

解决方案

对于 IE,您需要将变换设置为属性而不是 CSS 样式.

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

<头><脚本>window.onload = function() {document.getElementById("abc").setAttribute("transform", "translate(100, 100)")};<身体><div><svg width="200" height="200"><g id="abc"><polygon points="14,7 0,14 0,0"></polygon></svg>

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>

解决方案

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>

这篇关于javascript 中的 SVG 转换转换在 IE 11 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆