admin管理员组文章数量:1332359
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 badges1 Answer
Reset to default 6To 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
});
本文标签: javascriptRaphaeljshow to select an elementStack Overflow
版权声明:本文标题:javascript - Raphael.js, how to select an element? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742318107a2452224.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论