So für meine Aufgabe habe ich eine Webseite, wo ich eine Nummer eingeben und wählen Sie eine Form und die gewählte Anzahl Menge der gewählten Form wird angezeigt und durchlaufen eine Set-Animation. Nach der Animation wird die Form verschwinden, aber zuvor sollte die Form auch verschwinden, wenn sie angeklickt wird. Ich habe versucht, die remove() -Funktion zu verwenden, kann dies aber nicht richtig machen. Bitte helfen Sie.Entfernen Sie ein SVG-Element beim Klicken
Hier ist mein javascript:
draw = function() {
var typed = $('#howmany').val()
var shape = $('#shape').val()
var SVG = $("svg");
var x, y;
for (var i = 0; i < typed; i++) {
x = Math.random() * 350
y = Math.random() * 350
if (shape == 'a') {
pattern = paper.circle(25, 25, 25)
}
if (shape == 'b') {
pattern = paper.rect(10, 10, 50, 50)
}
if (shape == 'c') {
pattern = paper.path('M25,0 L50,50, L0,50 Z')
}
color_attr = {
'fill': '#BB7'
}
position_attr = {
'transform': 't' + x + ',' + y
}
pattern.attr(color_attr)
pattern.animate(position_attr, 2000)
pattern.click(remove())
setTimeout(function(){
SVG.find("circle").remove();
SVG.find("rect").remove();
SVG.find("path").remove();
}, 2000);
}
}
setup = function() {
paper = Raphael('svg1', 400, 400)
$('button').click(draw)
}
jQuery(document).ready(setup)
Hier ist die Geige: https://jsfiddle.net/o6e2yu5b/3/