我用Jquery制作了一个粒子生成器,它工作正常,但它有点CPU猪。任何建议表示赞赏。jquery粒子发生器
function particles() {
$.each($('.particles'), function() {
if ($(this).css("opacity") == 0) {
$(this).remove();
}
});
var particleSize = Math.floor(Math.random() * 4 + 1);
var speed = Math.floor(Math.random() * 5000 + 3000);
var distance = Math.floor(Math.random() * 500 + 200);
var fallOffSpeed = speed/2;
var fallOff = distance + distance/2;
$('body').prepend($($('<div>', {
"class" : "particles",
"height": particleSize,
"width": particleSize
}).css({
"background-color": "red",
"position": "absolute",
"top": Math.floor(Math.random() * 39),
"z-index": "-1"
}).animate({
"left": distance
}, speed, 'linear').animate({
"left": fallOff,
"opacity" : "0"
}, fallOffSpeed, 'linear')));
setTimeout(particles, 1000);
}
你的小提琴演示没有在github上工作,但在浏览器中的画布是很酷的thx。 – colemande 2012-04-04 14:37:11
演示现在已更新并托管在专用位置 – 2015-10-12 08:26:09