私はこのコードがランダムにいくつかのdivを作成することを発見しました:
(function makeDiv(){
var divsize = ((Math.random()*100) + 50).toFixed();
var color = '#'+ Math.round(0xffffff * Math.random()).toString(16);
$newdiv = $('<div/>').addClass("destruct").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(500, function(){
makeDiv();
});
})();
しかし、ホバー時にdivを1つずつ黒に変えてほしい。
$(document).ready(function() {
$('.destruct').hover( function(){
$('.destruct', this).css({background: '#000'});
});
});
しかし、それは機能しません...