javascript 新手,使用 Raphaël 库。我使用的 SVG 图像有一堆不同颜色的方块。我想为每种颜色设置不同的集合(例如 bluepath、pinkpath)并共享相同的悬停和单击功能。弹出框工作正常,但我不确定如何加入多个数组以共享相同的悬停和单击功能。如果有人愿意帮助我,我将非常感激...... :)
arr = new Array();
for (var block in bluepaths) {
var obj = r.path(bluepaths[block].path);
obj.attr(attributes);
arr[obj.id] = block, attributes = {
fill: '#00CCFF',
stroke: '#3899E6',
'stroke-width': 1,
'stroke-linejoin': 'round'
}
}
arr = new Array();
for (var blocktwo in pinkpaths) {
var obj = r.path(pinkpaths[blocktwo].path);
obj.attr(attributes);
arr[obj.id] = blocktwo, attributes = {
fill: '#00F',
stroke: '#3899E6',
'stroke-width': 1,
'stroke-linejoin': 'round'
}
obj.hover(function () {
this.animate({ fill: '#fff' }, 300);
}, function () {
this.animate({ fill: attributes.fill }, 300);
}).click(function () {
document.location.hash = arr[this.id];
var point = this.getBBox(0);
$('#map').next('.point').remove();
$('#map').after($('<div />').addClass('point'));
$('.point').html(bluepaths[arr[this.id]].name).prepend(
$('<a />').attr('href', '#').addClass('close').text('Close')
).prepend(
$('<img />').attr('src', 'flags/' + arr[this.id] + '.png')
).css({
left: point.x + (point.width / 2) - 80,
top: point.y + (point.height / 2) - 20
}).fadeIn();
});
$('.point').find('.close').live('click', function () {
var t = $(this),
parent = t.parent('.point');
parent.fadeOut(function () {
parent.remove();
});
return false;
});