如何在具有特定类的每个元素上绘制拉斐尔图

How to have raphael graph on each element with a certain class?

本文关键字:元素 绘制      更新时间:2023-09-26

我刚开始研究Raphael,每个教程都说你可以通过这样做来绘制一个元素:

element = Raphael(elementId); 

现在假设我有一堆<div>class='icon',我希望用Raphael在这个div的所有出现上绘制相同的图像。我该怎么做?

您可以设置一个"each"函数,在所有图标上循环并在每个图标上绘制。像这样,

var papers = []
$(".icon").each(function(index, element){
  papers.push(Raphael(element, "100%", "100%"));
  papers[index].rect(x,y,height,width); //replace this with the code you will use to draw your icon.
});

这应该有效,但如果你有任何问题,请发表评论。