-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJS7.html
More file actions
99 lines (84 loc) · 2.42 KB
/
JS7.html
File metadata and controls
99 lines (84 loc) · 2.42 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task 7 JavaScript</title>
<style>
#container {
text-align: center;
margin-top: 280px;
font-weight: bold;
color: blue;
}
#i1 {
position: absolute;
left: 100px;
top: 150px;
}
</style>
</head>
<body>
<center><h1>Task-7</h1></center>
<div id="container">
<img id="i1" src="..\Javascript\images\Train.jpg" />
</div>
<div id="container">
<form>
<center>
<p><h1>Click the below button to handle animation</h1></p>
<input type="button" onClick="timer()" value="Start">
<input type="button" onClick="reset1()" value="Stop">
</center>
</form>
</div>
<center>
<div id="msg"></div>
</center>
<script >
var dir = 'right';
var my_time;
function reset1() {
clearTimeout(my_time);
document.getElementById('i1').style.left = "100px";
document.getElementById('i1').style.top = "100px";
document.getElementById("msg").innerHTML = "";
}
function disp() {
var step = 5;
var x = parseInt(document.getElementById('i1').style.left);
if (x >= 2000) {
dir = 'left';
}
if (x <= 100) {
dir = 'right';
}
if (dir == 'right') {
x = x + step;
} else {
x = x - step;
}
document.getElementById('i1').style.left = x + "px";
}
function timer() {
disp();
var x = parseInt(document.getElementById('i1').style.left);
document.getElementById("msg").innerHTML = "X: " + x;
my_time = setTimeout(timer, 10);
}
function startMoving() {
if (!my_time) {
timer(); // Start the timer
}
}
function stopMoving() {
clearTimeout(my_time);
my_time = null;
}
window.onload = function () {
reset1(); // Reset image position on page load
};
</script>
</body>
</html>