我想生成已知数量的div的属性,但我可以弄清楚我哪里出错了。我曾尝试现在是:如何将随机值放入使用JQuery的css属性中?
$(document).ready(function(){
for(var i=1; i<=7; i++)
{
var randBottom = Math.ceil(Math.random()*200);
var randHeight = Math.ceil(Math.random()*300)+200-randBottom;
var randWidth = Math.ceil(Math.random()*50)+20;
var oceanWidth= $("#ocean").css(["width"]);
var randLeft= Math.ceil(Math.random()*oceanWidth)-randWidth;
var cssObj = {
'bottom' : randBottom+'px',
'height' : randHeight+'px',
'widht' : randWidth+'px
};
$("#bubble"+i).css(cssObj);
}
});
Here是一个完整的工作正在进行样品。
工作对我来说:http://jsfiddle.net/JdkPb/ –