2010-11-16 83 views
2

我用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); 

}

回答

3

我只是从一个元素产生的颗粒创造了一个非常小的jQuery plugindemo

我的插件还利用CSS3动画感谢jquery.animate-enhanced

的(你应该可以在IE中使用画布this kind of thing

+0

你的小提琴演示没有在github上工作,但在浏览器中的画布是很酷的thx。 – colemande 2012-04-04 14:37:11

+1

演示现在已更新并托管在专用位置 – 2015-10-12 08:26:09