如何使用jquery或css轻松创建移动粒子动画

如何使用jquery或css轻松创建移动粒子动画,jquery,animation,scroll,Jquery,Animation,Scroll,我有一个横幅,其中粒子通过jquery.bgcroll.js水平移动,代码如下 (function() { jQuery.fn.bgscroll = jQuery.fn.bgScroll = function( options ) { if( !this.length ) return this; if( !options ) options = {}; if( !window.scrollElements ) window.scrollElements = {};

我有一个横幅,其中粒子通过jquery.bgcroll.js水平移动,代码如下

(function() {
jQuery.fn.bgscroll = jQuery.fn.bgScroll = function( options ) {

    if( !this.length ) return this;
    if( !options ) options = {};
    if( !window.scrollElements ) window.scrollElements = {};

    for( var i = 0; i < this.length; i++ ) {

        var allowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        var randomId = '';
        for( var l = 0; l < 5; l++ ) randomId += allowedChars.charAt( Math.floor( Math.random() * allowedChars.length ) );

            this[ i ].current = 0;
            this[ i ].scrollSpeed = options.scrollSpeed ? options.scrollSpeed : 70;
            this[ i ].direction = options.direction ? options.direction : 'h';
            window.scrollElements[ randomId ] = this[ i ];

            eval( 'window[randomId]=function(){var axis=0;var e=window.scrollElements.' + randomId + ';e.current -= 1;if (e.direction == "h") axis = e.current + "px 0";else if (e.direction == "v") axis = "0 " + e.current + "px";else if (e.direction == "d") axis = e.current + "px " + e.current + "px";jQuery( e ).css("background-position", axis);}' );

            setInterval( 'window.' + randomId + '()', options.scrollSpeed ? options.scrollSpeed : 70 );
        }

        return this;
    };
  })(jQuery);
(函数(){
jQuery.fn.bgcroll=jQuery.fn.bgcroll=function(选项){
如果(!this.length)返回此;
如果(!options)options={};
如果(!window.scrollElements)window.scrollElements={};
for(var i=0;i
用法:jQuery('.particles').bgcroll({scrollSpeed:90,direction:h'})

这正是我所需要的,但过了15分钟,我的页面就因为这个而崩溃、被丢弃了

有没有简单的方法可以创建相同的移动动画而不会导致页面崩溃


提前感谢。

崩溃通常是由递归引起的。试着替换

jQuery.fn.bgscroll = jQuery.fn.bgScroll = function( options )


它停止工作@Inpyo-Jeon。现在我收到了这个错误jQuery(…)。bgscroll不是一个函数。@Anahit DEV Try replace(function()-->(function($)。如果它不起作用,请发布整个代码。不,它没有解决问题。您已将所有代码粘贴到我的问题@Inpyo Jeon中
jQuery.fn.bgScroll = function( options )