Simultaneously squares on pages fading in and out

2019-09-05 22:38发布

Objective: Display many squares or any object (words, images, etc.) simultaneously fading in and out.

The example below shows only one square at a time flashing in and out. http://jsfiddle.net/redler/QcUPk/8/

(function makeDiv(){
    var divsize = ((Math.random()*100) + 50).toFixed();
    var color = '#'+ Math.round(0xffffff * Math.random()).toString(16);
    $newdiv = $('<div/>').css({
        'width':divsize+'px',
        'height':divsize+'px',
        'background-color': color
    });

    var posx = (Math.random() * ($(document).width() - divsize)).toFixed();
    var posy = (Math.random() * ($(document).height() - divsize)).toFixed();

    $newdiv.css({
        'position':'absolute',
        'left':posx+'px',
        'top':posy+'px',
        'display':'none'
    }).appendTo( 'body' ).fadeIn(100).delay(300).fadeOut(200, function(){
       $(this).remove();
       makeDiv(); 
    }); 
})();

So if there was an array $data displaying names from a database, how would this be accomplished showing for examples James, John, Mary, and Peter. So for every entry a user enters in a form the name shows flashing in and out of the squares at different times all at once.

0条回答
登录 后发表回答