[英]Raphael.js attributes and VML
With Raphael I would like to create a rectangle with an Id attribute like the example below. 我想使用Raphael创建一个具有Id属性的矩形,如下例所示。
<rect id="aRect" x="10" y="10" width="50" height="50" r="2" rx="2" ry="2"/>
To create the rectangle I can use code like this 要创建矩形,我可以使用如下代码
var elem = _paper.rect(10, 10, 50, 50, 2);
and set the Id using code like this 并使用这样的代码设置ID
elem[0].setAttributeNS(null, 'id', 'aRect');
or with code like this 或像这样的代码
elem.node.id = 'aRect';
now raphael falls back to vml on older IE's right how can I add an id attribute that also caters for the vml case or does this code work for that too? 现在raphael在较旧的IE上又回到了vml,我如何添加一个也可以满足vml情况的id属性,或者该代码是否也适用于此?
After reading on MS page here I implemented this solution for setting the Id. 在此处阅读MS页面后,我实现了用于设置ID的解决方案。
function setId(el, id){
if(el === null || typeof el !== 'object') return;
if(Raphael.type === 'SVG') {
el[0].setAttributeNS(null, 'id', id);
}
else if(Raphael.type === 'VML') {
el[0].id = id;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.