jquery粒子生成器

标签 jquery css animation

我用 Jquery 制作了一个粒子生成器,它工作正常,但它有点占用 CPU。如有任何建议,我们将不胜感激。

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

}

最佳答案

我刚刚创建了一个非常小的jQuery plugin用于从元素生成粒子 ( demo )

由于 jquery.animate-enhanced,我的插件还利用了 CSS3 的动画

(您应该能够通过 this kind of thing 在 IE 中使用 Canvas )

关于jquery粒子生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4199904/

相关文章:

css - 将 Font Awesome 图标添加到 Bootstrap 4 选择

css - 将 facebook 共享图标替换为超棒的 facebook 图标

c# - WPF 旋转形状。替代 PlaneProjection?

jquery - Mongoose 插入\u0000

jquery - 如何在 rails 3.1 上安装 jQuery

javascript - 将网址/链接粘贴到文本框中时预览小图片

javascript - 页面加载后,如何根据 jQuery 中的类更改图像源

css - 为什么我的 Sprite 在 iOS/Android 上不工作,但在 Safari/Chrome 上工作正常?

android - 如何在android中进行 Activity 淡入淡出过渡

javascript - react .js : Non-CSS animations