Javascript 使这些功能与ie9兼容
我在ie9中尝试了这些函数,并将ie10设置为ie9仿真。 在这些函数中,doc是svg文档根元素。 加法变换Javascript 使这些功能与ie9兼容,javascript,dom,internet-explorer-9,Javascript,Dom,Internet Explorer 9,我在ie9中尝试了这些函数,并将ie10设置为ie9仿真。 在这些函数中,doc是svg文档根元素。 加法变换 /** * Add a <g> element that envelop all SCG elements and makes the viewbox transformMatrix descend on all elements */ function addSvgTransform(doc, matrix) { matrix[3] = mat
/**
* Add a <g> element that envelop all SCG elements and makes the viewbox transformMatrix descend on all elements
*/
function addSvgTransform(doc, matrix) {
matrix[3] = matrix[0] = (matrix[0] > matrix[3] ? matrix[3] : matrix[0]);
if (!(matrix[0] !== 1 || matrix[3] !== 1 || matrix[4] !== 0 || matrix[5] !== 0)) return;
// default is to preserve aspect ratio
// preserveAspectRatio attribute to be implemented
var el = document.createElement('g');
while (doc.firstChild != null) {
var node = doc.firstChild;
el.appendChild(node);
}
el.setAttribute('transform','matrix(' + matrix[0] + ' ' + matrix[1] + ' ' + matrix[2] + ' ' + matrix[3] + ' ' + matrix[4] + ' ' + matrix[5] + ')');
doc.appendChild(el);
}
失败点:
el是一个document.element。
ie9不希望将SVG中的任何其他节点附加到此类节点上,也不希望将此节点直接附加到SVG文档上。
我们的doc变量没有createElement方法。
此函数的目的是在文档根和所有其他元素之间添加一个“G”元素
这个问题解决了
正在执行var el=document.createElement'g';==>:var el=doc.ownerDocument.createElement'g'
ParseUseDirections
function parseUseDirectives(doc) {
var nodelist = doc.getElementsByTagName('use');
while (nodelist.length) {
var el = nodelist[0],
xlink = el.getAttribute('xlink:href').substr(1),
x = el.getAttribute('x') || 0,
y = el.getAttribute('y') || 0,
el2 = doc.getElementById(xlink).cloneNode(true),
currentTrans = (el.getAttribute('transform') || '') + ' translate(' + x + ', ' + y + ')',
parentNode;
for (var j = 0, attrs = el.attributes, l = attrs.length; j < l; j++) {
var attr = attrs.item(j);
if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') continue;
if (attr.nodeName === 'transform') {
currentTrans = currentTrans + ' ' + attr.nodeValue;
}
else {
el2.setAttribute(attr.nodeName, attr.nodeValue);
}
}
el2.setAttribute('transform', currentTrans);
el2.removeAttribute('id');
parentNode = el.parentNode;
parentNode.replaceChild(el2, el);
}
}
此函数失败,因为doc没有doc.getElementById方法
编辑:这里的问题是ie9中没有nodesByID方法。要使用它,我必须指定id属性的类型为id或XS:id。
要做到这一点,我必须添加一个xsd或dtd模式,如果我理解得很好的话。
所以我想在解析文档之前添加这个符号。
我应该写什么
<xsd:attribute name="id" type="xsd:ID" />
在哪里?怎样有什么想法吗?帮助?好的,先完成。from:var el=document.createElement'g';to:var el=doc.ownerDocument.createElement'g';