È possibile essere in grado di trascinare e rilasciare oggetti diversi da semplici cerchi e rettangoli intorno a una pagina utilizzando Raphael js?Creazione di percorsi e immagini trascinabili in Raphael js
Voglio aggiungere percorsi e immagini che è possibile spostare, ma è difficile. Mi piacerebbe lavorare su questo con Raphael per il suo supporto con le interfacce touch.
Ecco il codice
<script>
window.onload = function() {
var R = Raphael(0, 0, "100%", "100%"),
r = R.circle(100, 100, 50).attr({fill: "hsb(0, 1, 1)", stroke: "none", opacity: .5}),
g = R.circle(210, 100, 50).attr({fill: "hsb(.3, 1, 1)", stroke: "none", opacity: .5}),
b = R.circle(320, 100, 50).attr({fill: "hsb(.6, 1, 1)", stroke: "#fff", "fill-opacity": 0, "stroke-width": 0.8, opacity: .5}),
p = R.path("M 250 250 l 0 -50 l -50 0 l 0 -50 l -50 0 l 0 50 l -50 0 l 0 50 z") .attr({fill: "hsb(.8, 1, 1)", stroke: "none", opacity: .5});
var start = function() {
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.animate({r: 70, opacity: .25}, 500, ">");
},
move = function (dx, dy) {
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function() {
this.animate({r: 50, opacity: .5}, 500, ">");
};
R.set(r, g, b, p).drag(move, start, up);
};
</script>
Grazie. Ma c'è un modo per conoscere la posizione finale (assoluta) delle forme? – Yako
Yako, puoi usare getBBox() – Dan
translate è deprecato, vedi la mia risposta per fare questo con transform –