-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask-8.html
More file actions
42 lines (41 loc) · 1.48 KB
/
Task-8.html
File metadata and controls
42 lines (41 loc) · 1.48 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
<!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>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
</head>
<body>
<div class="mt-5 position-relative" >
<div id="animate" class="position-relative"> <img src="Train.jpg" ></div></div>
<div class="text-center mt-5 text-primary fs-3"><b>Click the following buttons to handle animation</b></div>
<div class="row w-25 m-auto ">
<button onclick="myMove()" class="col m-2 p-2 btn btn-outline-dark" >Start</button>
<button class="col m-2 p-2 btn btn-outline-dark" onclick="stop()">Stop</button></div>
<script>
let id = null;
let pos = 0;
function myMove() {
const elem = document.getElementById("animate");
if(pos==1000)
pos=0;
clearInterval(id);
id = setInterval(frame, 5);
function frame() {
if (pos == 1000) {
clearInterval(id);
} else {
pos++;
elem.style.left = pos + "px";
}
}
}
function stop()
{
clearInterval(id);
}
</script>
</body>
</html>