关于如何在 jQuery 对象上调用 Raphael 方法有一个很好的答案。它完美地工作。但我需要更多功能。我想在单击按钮时显示形状宽度某些属性。在那个答案中,我只能影响数组中的所有形状。我怎样才能过滤它们?我使用了这段代码:
$("button").click(function() {
$.each(cottages_array, function(i, c){
c.animate({fill: '#55bfe1', opacity: 1}, speed_anim_in);
});
});
我的形状有属性类型,我只想突出显示特定类型的形状(例如 A 型)。在循环内部,我可以用不同的颜色填充不同的类型,但我不知道如何使用 jQuery 对循环外的点击应用任何条件。
for (var j = 0; j < obj.cottages.length; j++) {
var obj_cottages = obj.cottages[j],
my_path = canvas.path(obj_cottages.coords);
my_path
.attr({stroke: "none", fill: cottage_color_start, "fill-opacity": 0.8, opacity: 0, cursor: "pointer"})
.data('type', obj_cottages.type)
if (obj_cottages.type == 'A') {
my_path
.attr({stroke: "none", fill: "#fff", "fill-opacity": 0.8, opacity: 0, cursor: "pointer"})
}
我花了一整天的时间试图弄清楚如何做到这一点,但我一点运气都没有。