2

I'm trying to use Raphael.js for a map. I would like to be able to click a button outside the map to get a set of states to become a different color. I've tried adjusting a jsfiddle (see below) for a while, but just can't get it to work. What am I missing?

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);
});

The JS fiddle is here.

Thank you for any suggestions

4

1 回答 1

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);
};
于 2013-07-01T14:22:52.163 回答