javascript - Raphael.js, how to select an element? - Stack Overflow

In Raphael,js, how can I select an element? For example, If I have an rectangular, how to select it? In

In Raphael,js, how can I select an element? For example, If I have an rectangular, how to select it? In Raphael, is there any way to select element like the selection of DOM element using jQuery?

In Raphael,js, how can I select an element? For example, If I have an rectangular, how to select it? In Raphael, is there any way to select element like the selection of DOM element using jQuery?

Share Improve this question edited Sep 11, 2020 at 10:19 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked May 10, 2011 at 8:53 LeemLeem 18.3k39 gold badges112 silver badges164 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

To select an svg DOM element, supposing a node of the raphael element has an ID, you can do it in the 'jQuery' mode by $('#ID') or in the 'native' way document.getElementById('ID').

Moreover, using raphael handling events is very simple, for example when you click on a rectangle you can 'select' it, in this way (demo here => http://jsfiddle/steweb/zMYU8/):

markup:

<div id="canvas"></div>

js:

var selected = null; //var to store selected element

//initialize the raphael canvas and store it in a var
var canvas = Raphael(document.getElementById("canvas"), 320, 200);

//first rectangle
var r = canvas.rect(10, 10, 50, 50).attr("fill", "#FFFF22");

//second rectangle
var r1 = canvas.rect(70, 70, 50, 50).attr("fill", "#FFFF22");

//first rectangle click
r.click(function(){
  //change attributes
  r1.attr("stroke","black");  
  r.attr("stroke","green");
  selected = r; //update selected var
});

//second rectangle click
r1.click(function(){
  //change attributes
  r.attr("stroke","black");  
  r1.attr("stroke","green");
  selected = r1; //update selected var
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742318108a4421248.html

相关推荐

  • javascript - Raphael.js, how to select an element? - Stack Overflow

    In Raphael,js, how can I select an element? For example, If I have an rectangular, how to select it? In

    15小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信