【发布时间】:2017-04-26 07:56:55
【问题描述】:
因此,对于我的作业,我有一个网页,我在其中输入一个数字并选择一个形状,所选形状的所选数字数量将出现并通过一组动画。动画结束后,形状会消失,但在此之前,如果单击,形状也会消失。我尝试使用 remove() 函数,但无法做到这一点。请帮忙。
这是我的 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)
【问题讨论】:
标签: javascript jquery html svg raphael