-
Notifications
You must be signed in to change notification settings - Fork 1
/
shiftBox.html
executable file
·101 lines (101 loc) · 2.18 KB
/
shiftBox.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<html>
<head>
<title>Shift Box</title>
<style>
div.d00
{
border: 25px solid purple;
}
</style>
</head>
<body>
<div class="d00" id="d01" style="width:350px;height:550px;background:pink;">
<div id="d02" style="width:25px;height:25px;background:red;top:25px;left:25px;position:relative;">
</div>
</div>
<form>
<table>
<tr >
<td><input type="button" value=" up " onclick="Up()"></td>
<td><input type="button" value="down " onclick="Down()"></td>
</tr>
<tr>
<td><input type="button" value="left " onclick="Left()"></td>
<td><input type="button" value="right" onclick="Right()"></td>
</tr>
</table>
</form>
<script>
var id1;
var idu;
var idr;
var idd;
function Left()
{
idl = setInterval(function(){moveLeft();},50);
}
function Right()
{
idr = setInterval(function(){moveRight();},50);
}
function Up()
{
idu = setInterval(function(){moveUp();},50);
}
function Down()
{
idd = setInterval(function(){moveDown();},50);
}
function moveLeft()
{
var element = document.getElementById("d02");
if(parseInt(element.style.left)>25)
{
element.style.left = (parseInt(element.style.left) - 20) +"px";
}
else
{
clearInterval(idl);
}
}
function moveRight()
{
var element = document.getElementById("d02");
var e2 = document.getElementById("d01");
if(parseInt(element.style.left)<parseInt(e2.style.width)-45)
{
element.style.left = (20 + parseInt(element.style.left)) +"px";
}
else
{
clearInterval(idr);
}
}
function moveUp()
{
var element = document.getElementById("d02");
if(parseInt(element.style.top)>25)
{
element.style.top = ( parseInt(element.style.top) - 20) +"px";
}
else
{
clearInterval(idu);
}
}
function moveDown()
{
var element = document.getElementById("d02");
var e2 = document.getElementById("d01");
if(parseInt(element.style.top)<parseInt(e2.style.height)-45)
{
element.style.top = (20 + parseInt(element.style.top)) +"px";
}
else
{
clearInterval(idd);
}
}
</script>
</body>
</html>