Raphael.js点击活动

时间:2013-07-01 14:07:05

标签: javascript events raphael set

我正在尝试使用Raphael.js来制作地图。我希望能够单击地图外部的按钮以使一组状态变为不同的颜色。我试过调整一个jsfiddle(见下文)一段时间,但只是无法让它工作。我错过了什么?

HTML

<button id="show">Show</button>

JS

    var paper = Raphael(10, 50, 960, 560);
var attr = {fill: 'blue',
stroke: '#000',
'stroke-width': 5,
cursor: 'pointer'};

var elementSet = paper.set();
var cn = {};
   cn.a = paper.path("M339.098,175.503c0,0-55.555,58.823-16.34,75.163s227.451,49.02,227.451,49.02s67.321-25.49,47.713-50.98s-71.896-78.432-71.896-78.432L339.098,175.503z").attr(attr);
   cn.b = paper.path("M548.902,306.876c0,0-209.15-32.026-228.758-46.405s-27.451-27.451-20.262-42.484s26.797-44.444,26.797-44.444l-41.83-86.928l-76.471,77.125c0,0-25.49,169.935,48.366,171.242s292.157-4.575,292.157-4.575V306.876z").attr(attr);
   cn.c = paper.path("M296.614,86.614l38.562,83.66l194.771-7.843l75.817,81.7c0,0,130.066-84.967,73.203-118.301S503.15,48.706,463.935,51.974S296.614,86.614,296.614,86.614z").attr(attr);

 elementSet.push(cn.a, cn.b); //define what is in the set


$('#show').on( 'click', function() {
   elementSet.animate({
            fill: '#000'
   }, 500);
});

JS小提琴是here

感谢您提出任何建议

1 个答案:

答案 0 :(得分:5)

请改为尝试:

var paper = Raphael(10, 50, 960, 560);
var attr = {
    fill: 'blue',
    stroke: '#000',
        'stroke-width': 5,
    cursor: 'pointer'
};

var elementSet = paper.set();
var cn = {};
cn.a =     paper.path("M339.098,175.503c0,0-55.555,58.823-16.34,75.163s227.451,49.02,227.451,49.02s67.321-25.49,47.713-50.98s-71.896-78.432-71.896-78.432L339.098,175.503z").attr(attr);
cn.b = paper.path("M548.902,306.876c0,0-209.15-32.026-228.758-46.405s-27.451-27.451-20.262-42.484s26.797-44.444,26.797-44.444l-41.83-86.928l-76.471,77.125c0,0-25.49,169.935,48.366,171.242s292.157-4.575,292.157-4.575V306.876z").attr(attr);
cn.c = paper.path("M296.614,86.614l38.562,83.66l194.771-7.843l75.817,81.7c0,0,130.066-84.967,73.203-118.301S503.15,48.706,463.935,51.974S296.614,86.614,296.614,86.614z").attr(attr);

elementSet.push(cn.a, cn.b); //define what is in the set

var button = document.getElementById('show');

button.onclick = function () {
    elementSet.animate({
        fill: '#000'
    }, 500);
};