问题
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.
来源:https://stackoverflow.com/questions/22726914/simultaneously-squares-on-pages-fading-in-and-out-with-javascript