Dans Raphael, js, comment puis-je sélectionner un élément? Par exemple, si j'ai un rectangle, comment le sélectionner? Dans Raphael, est-il possible de sélectionner un élément comme la sélection de l'élément DOM en utilisant jQuery?Raphael.js, comment sélectionner un élément?
4
A
Répondre
6
Pour sélectionner un élément DOM svg, en supposant qu'un noeud de l'élément raphael possède un ID, vous pouvez le faire dans le mode 'jQuery' par $('#ID')
ou de la manière 'native' document.getElementById('ID')
.
De plus, en utilisant les événements de manipulation de raphael est très simple, par exemple lorsque vous cliquez sur un rectangle, vous pouvez 'sélectionner' il, de cette manière (démo ici =>http://jsfiddle.net/steweb/zMYU8/):
balisage:
<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
});
Questions connexes
- 1. Comment sélectionner un élément?
- 2. Comment sélectionner un élément imbriqué
- 3. Comment sélectionner un élément ajouté
- 4. Raphael.js Comment utiliser le fichier CSS avec Raphael.js?
- 5. Raphael.js - redimensionner un élément au fil du temps
- 6. Mise à jour des informations HTML via un élément Raphael.JS
- 7. Comment sélectionner un élément de menu dans un élément d'exécution?
- 8. raphael.js crop image
- 9. Raphael.js Comment supprimer clickler handler?
- 10. Comment sélectionner un élément dans jComboBox
- 11. Comment sélectionner un élément UNTAG dans CSS
- 12. Comment sélectionner le corps sauf un élément?
- 13. comment sélectionner un élément d'un ListView?
- 14. Comment sélectionner un élément d'une liste DL
- 15. Comment sélectionner un élément introduit par ajax
- 16. Comment sélectionner un élément dans l'arborescence Silverlight?
- 17. jquery: comment sélectionner un élément de innerHTML?
- 18. Comment sélectionner un élément dans ListBox
- 19. XML comment sélectionner et afficher un élément?
- 20. Comment sélectionner un élément généré par jQuery?
- 21. Comment sélectionner un élément par son contenu?
- 22. Comment sélectionner un seul élément dans jQuery?
- 23. Raphael.js comment définir l'attribut pour un chemin?
- 24. Sélectionner un élément dans Asp.Net?
- 25. Comment sélectionner cet élément td?
- 26. JQuery sélectionner un élément dans un td
- 27. Sélectionner aléatoirement un élément dans une liste
- 28. Comment sélectionner un élément dans un ListView par programmation?
- 29. Comment sélectionner un élément aléatoire dans un tableau
- 30. comment sélectionner un élément dans un espace de noms spécifique?