js 碰碰球

來源:互聯網
上載者:User

標籤:order   padding   interval   document   type   size   ext   create   idt   

<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}

#box {
width: 700px;
height: 500px;
border: 2px solid black;
position: relative;
top: 100px;
left: 200px;
}

.qq {
position: absolute;
width: 30px;
height: 30px;
background-color: red;
border-radius: 50%;
background:red;
background-size: 30px 30px;
}
</style>
</head>

<body style="background: url(img/timg.jpg)no-repeat;background-size:100% 700px ; ">
<div id="box">

</div>

<script type="text/javascript">

function Arr(left, top) {

this.box = document.getElementById("box")
this.qiu = document.createElement("p");
this.box.appendChild(this.qiu);
this.qiu.className = "qq"
this.lol = 30
this.left = left || Math.random() * (box.clientWidth - this.lol);
this.top = top || Math.random() * (box.clientHeight - this.lol);
this.qiu.style.left = this.left + "px"
this.qiu.style.top = this.top + "px"
this.oX = parseInt(Math.random() * 1+5) ;
this.oY = parseInt(Math.random() * 1+4) ;

this.tex()
}
Arr.prototype.tex = function() {

var sty = this
var jishi = setInterval(function() {

sty.left += sty.oX
sty.top += sty.oY
sty.qiu.style.left = sty.left + "px"
sty.qiu.style.top = sty.top + "px"
if(sty.left >= box.clientWidth - sty.lol || sty.left <= 0)
{ sty.oX = -sty.oX }

if(sty.top >= box.clientHeight - sty.lol || sty.top <= 0) { sty.oY = -sty.oY}
}, 10)
console.log(sty.left)

}

for (var i = 0; i <5; i++) {
new Arr()
}


</script>

</body>

</html>

js 碰碰球

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.