运用随机函数实现随机显示颜色和位置
$(document).ready(function(){
function getPosition(){
var wid = $(window).width()-40;
var hei = $(window).height()-40;
rdWid =Math.floor(Math.random()*wid) ;
rdHei = Math.floor(Math.random()*hei);
}
function getColor (){
var col = "#"
for(var i = 0;i<6;i++){
var num = [0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"];
var rdColor = Math.floor(Math.random()*16);
col+=num[rdColor];
}
return col;
}
$("#box").mouseover(function(){
getPosition();
$(this).css({"left":rdWid,"top":rdHei,"background-color":getColor()});
})
})