forked from zuobaiquan/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
60 lines (59 loc) · 1.81 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<html>
<head>
<title></title>
<meta name="name" content="content" charset="utf-8"/>
<style media="screen" type="text/css">
*{margin:0;padding:0;}
</style>
<script type="text/javascript">
//绘制地图坐标
function Map(){
//私有成员
var w=800;
var h=400;
this.showMap=function(){
//创建div、设置css样式、追加到body
var tu=document.createElement('div');
tu.style.width=w;
tu.style.height=h;
tu.style.backgroundImage="url('bg.png')";
document.body.appendChild(tu);
}
}
//绘制随机点
function Food(){
var len=20;
this.showFood=function(){
//创建div、设置css样式、追加到body
var Randot=document.createElement('div');
Randot.style.width=Randot.style.height=len+'px';
Randot.style.borderRadius=len+'px';
Randot.style.backgroundColor="green";
//随机点设置绝对定位
//随机点位置随机摆放
//移动步进值
//随机点权值坐标 X轴(0-39) Y轴(0-19)
//随机点真实坐标
var xRandot=Math.floor(Math.random()*40);
var yRandot=Math.floor(Math.random()*20);
Randot.style.position='absolute';
Randot.style.left=xRandot*len+(len/2);
Randot.style.top=yRandot*len+(len/2);
document.body.appendChild(Randot);
}
}
window.onload=function(){
var map=new Map();
map.showMap();
var i=0;
while(i<10){
var fd=new Food();
fd.showFood();
i++;
}
}
</script>
</head>
<body>
</body>
</html>