【问题标题】:Raphaeljs path id inside a set attributes一组属性中的 Raphaeljs 路径 ID
【发布时间】:2013-09-19 04:38:14
【问题描述】:

我正在使用 Raphaeljs 绘制地图,并且我在一组路径中设置了路径,因为我希望它们都具有相同的属性并且一切都很好,但现在我想为每条路径设置一个 id,我做到了它到一个,但属性丢失了,所以我的问题是......有没有办法在具有设置属性的集合内有一个 path.id ?谢谢

这里是文件http://jsfiddle.net/tLSpv/2/

var paper = Raphael(0,0,540, 615);

var newmexico = paper.set();

newmexico.push(
paper.path("M343.249,11.503l-1.658,3.554l-0.474,16.822c0,0-3.554-0.711-5.449-0.711 s-5.686,3.554-5.449,4.265c0.237,0.711-1.895,13.268-1.895,14.215s3.554,4.502,3.317,5.449c-0.237,0.948-0.711,3.554-0.474,4.502 c0.237,0.948,0.711,7.345,0.474,9.477c-0.237,2.132,0.948,11.846-1.658,13.268h42.883v5.449h38.855h37.197V73.103l1.303-1.303V1.239 L340.643,1.18v4.4L343.249,11.503z").node.id = 'colfax';
).attr({    
            fill: '#F7F0EA',
            stroke: '#006599',
            'stroke-width': 1,
            cursor: 'pointer' 
 })

.hover(function () {
 this.animate({fill: '#006599'}, 300);
    },
    function () {
    this.animate({fill: '#F7F0EA'}, 300)
    }
);

【问题讨论】:

    标签: javascript raphael


    【解决方案1】:

    这是一个建议。将Raphaels data() 函数添加到您的属性列表顶部。

    经验:

    for (var i = 0, i < 5, i++) {
        paper.circle(10 + 15 * i, 10, 10)
             .attr({fill: "#000"})
             .data("i", i)
             .click(function () {
                alert(this.data("i"));
             });
    }
    

    这个小例子取自heredata 添加或检索与给定键关联的给定值。在这种情况下,"i" 是键,i 是值。

    这就是我为我的 Raphael 对象分配 id 的方式。祝你好运

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-05-29
    • 2014-10-25
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    相关资源
    最近更新 更多