的隨機位置,我發現這個代碼來創建一些格設置隨機:的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();
});
})();
但我想股利變黑上懸停,一個接一個。
$(document).ready(function() {
$('.destruct').hover(function(){
$('.destruct', this).css({background: '#000'});
});
});
但它不工作...
這裏是一個http://jsfiddle.net/q6L7C/2/
是的,謝謝你的工作! – Cat
你想在mouseout上恢復到真實的顏色嗎? –
不需要,但它可能對其他人有用。 :) – Cat