Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raphael js how to include multiple Icons per Site? with class instead of ID

How can i include multiple icons from Raphaël (http://raphaeljs.com/icons/) on one Site?

I haven't managed to include them via class="icon", just with id="icon". Because I ain't that good in JavaScript i searched the web but found nothing.

Only thing I found on the blog:

    bubble: "M16,5.333c-7.732,0-14,4.701-14,10.5c0,1.982,0.741,3.833,2.016,5.414L2,25.667l5.613-1.441c2.339,1.317,5.237,2.107,8.387,2.107c7.732,0,14-4.701,14-10.5C30,10.034,23.732,5.333,16,5.333z",

a = j[b]("column-1")[f]("h2");
for (var z = a.length; z--;) {
   l = a[z];
   l && g(l[f](i)[0], 32, 32).path(k.bubble).attr(m);
}

The .js http://dmitry.baranovskiy.com/site2.js

The blog http://dmitry.baranovskiy.com/

Because he uses the "bubble" in a span in front of every post.

Is there a way to include it with class instead of ID? This is how i include it via ID

var example = Raphael("example", 50, 60);
example.path("icon-string").attr({fill: "#fff", stroke: "#333"});

and then include it via

<span id="example">
like image 547
joe8 Avatar asked Jan 18 '12 18:01

joe8


1 Answers

You need to put your elements in an array and then loop over it:

var elements = document.querySelectorAll('.paper');
for (i=0; i<elements.length; i++) {
    paper = Raphael(elements[i], 50, 50)
    paper.path(bubble).attr({"fill": "#333"})
}

Or the jQuery version to make it compatible with IE 6 & 7

$('.paper').each(function(i){
        paper = Raphael($(this)[0], 50, 50)
        paper.path(bubble).attr({"fill": "#333"})
})

You can find a demo here: http://jsfiddle.net/CHEP9/

like image 182
methodofaction Avatar answered Oct 26 '22 23:10

methodofaction