這是用於我的計算課的作業。我有一堆隨機框,從一個給定區域內的隨機位置頂部開始。作業就是讓它們隨機地在屏幕頂部傳播,然後降低屏幕的高度。我管理第一部分,讓它們遍佈屏幕的頂部,但爲了降低屏幕的高度..我有一些有趣的結果,實際上讓我發笑。這裏是我的代碼,我認爲這個問題是在第62行:使用屏幕高度的動畫功能
<head>
<style>
body, html {
margin: 10px;
padding: 10px;
position: relative;
}
.box{
height: 50px;
width: 50px;
border: 1px solid black;
position: absolute;
}
#container{
position: relative;
height: 550px;
}
#box1{
left: 80px;
top: 0px;
background: blue;
}
#box2{
left: 120px;
top: 200px;
background: red;
}
</style>
</head>
<body>
<div id="header">
<p> score <span id="score">0</span></p>
</div>
<div id = "container">
<div id = "box1" class = "box"></div>
<div id = "box2" class = "box"></div>
</div>
<script src="http://code.jquery.com/jquery-1.11.1.js"> <!--Javascript below this line for speed-->
</script>
<script>
nBoxes = 2;
score = 0;
function addBoxes(){
for(i=nBoxes+1;i<nBoxes+30;i++){
$('#container').append('<div id="box' + i + '" class="box"></div>');
$('#box'+i).css('top',-Math.floor(Math.random()*20)).css('left',Math.random()*screen.width);
$('#box'+i).animate({height: "100%"},3000);
}
nBoxes+=30;
/*$(".box").dblclick(function(){
console.log($(this).attr("id"));
$(this).animate({opacity:0.1, marginLeft:"+=150px"
},5000);
}
)*/
$('.box').click(function(){
$(this).stop();
$(this).remove();
score += 1;
$('#score').html(score);
return false;
}
)
}
addBoxes();
setInterval(addBoxes,3000);
</script>
</body>
在此先感謝您的幫助。
的要求的的jsfiddle:http://jsfiddle.net/19f65ycd/
謝謝,這就是我一直在尋找:) – daltojam 2014-10-07 15:57:20