【问题标题】:Raphael.js attributes and VMLRaphael.js 属性和 VML
【发布时间】:2012-10-11 10:10:59
【问题描述】:

对于 Raphael,我想创建一个带有 Id 属性的矩形,如下例所示。

<rect id="aRect" x="10" y="10" width="50" height="50" r="2" rx="2" ry="2"/>

要创建矩形,我可以使用这样的代码

var elem = _paper.rect(10, 10, 50, 50, 2);

并使用这样的代码设置 ID

elem[0].setAttributeNS(null, 'id', 'aRect');

或者像这样的代码

elem.node.id = 'aRect';

现在 raphael 在较旧的 IE 上回退到 vml,如何添加一个也适用于 vml 情况的 id 属性,或者此代码是否也适用于此?

【问题讨论】:

    标签: javascript attributes svg raphael vml


    【解决方案1】:

    在阅读 MS 页面 here 后,我实施了这个解决方案来设置 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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-01
      • 2011-11-02
      • 2011-08-13
      • 2014-07-27
      • 2019-06-19
      • 1970-01-01
      • 2014-01-28
      • 1970-01-01
      • 2012-05-14
      相关资源
      最近更新 更多