循环遍历RaphaelJS集合

Looping through RaphaelJS sets

本文关键字:集合 RaphaelJS 遍历 循环      更新时间:2023-09-26

我正在尝试通过一系列RaphaelJS集进行循环。

我有一系列箭头形状(集合)。我希望能够循环遍历它们。

var migration1 = c.set(c.path("M129.045,368.584c0,0,19.155-13.9,23.374-50.593 c2.283-19.858-10.22-31.366-18.958-36.886").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M139.728,278.292L135.038 282.091 134.516 288.104 125.493 277.021 z").attr({fill: "#990000", "stroke-width": 0}), c.path("M136.059,375.577c0,0,42.113-48.3,94.441-84.818 c55.985-39.072,143.717-72.937,171.049-83.015").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M399.536,214.469L399.827 208.441 395.689 204.047 409.966 204.699 z").attr({fill: "#990000", "stroke-width": 0}));
var migration2 = c.set(c.path("M287.563,407.934 c0,0,26.391-73.864,66.459-135.858c30.304-46.886,62.735-75.691,76.743-86.947").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M430.854,192.14L429.326 186.301 424.063 183.347 437.881 179.696 z").attr({fill: "#990000", "stroke-width": 0}));
var migration3 = c.set(c.path("M106.872,237.5c0,0,82.633-29.237,261.38-61.119 c145.376-25.929,228.743-26.742,254.803-26.142").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M618.66,155.717L621.198 150.242 619.018 144.614 632 150.589 z").attr({fill: "#990000", "stroke-width": 0}), c.path("M106.872,237.5c0,0,95.407-26.3,178.93-25.373 c62.451,0.693,87.378,29.095,95.981,43.382").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M374.787,254.352L380.807 253.922 384.677 249.291 385.73 263.543 z").attr({fill: "#990000", "stroke-width": 0}));
var migration4 = c.set(c.path("M336,292 c11.139-4.582,18.674-13.417,31.977-14.868c8.351-0.911,34.987-3.037,34.05,10.528c-0.977,14.141-32.223,18.288-32.963,30.188 c-0.384,6.178,9.04,9.792,12.936,7.151 M387,351 c0.673-0.509,1.006-1.176,1-2").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}));
var migration5 = c.set(c.path("M117.073,329.436 c0,0,12.897-27.418,68.927-67.291c38.271-27.234,71.998-42.664,102.902-52.111").attr({fill: "none", "stroke-width": 3, stroke: "#990000"}), c.path("M286.465,216.615L287.142 210.618 283.295 205.968 297.5 207.535 z").attr({fill: "#990000", "stroke-width": 0}));

我试过:

for (i=1<=5;i++){
   this['migration'+i].hide();
}

…这样我就可以有一个按钮,按顺序显示它们:

var current=1;
$('#next').click(function(){
   this['migration'+current].hide();
   current++;
   this['migration'+current].show();
})

使用'this'似乎不正确,但我不确定如何连接集名称以瞄准它。

提前感谢。

你可以创建一个集合数组…

var migrations =[ c.set(...), c.set(...), c.set(...), c.set(...), c.set(...)];
那么你的代码看起来像:
var current=1;
$('#next').click(function(){
   migrations[current].hide();
   migrations[current++].show();
})

我使用以下方法来隐藏传递给函数的set作为'text':

function hideSet(set) { 
    set=eval(set);
    set.forEach( function(e){ e.hide(); } ) 
}

使用this来切换

hideSet('setname');