-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (48 loc) · 1.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Slider using JS</title>
<link rel="stylesheet" href="slider.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
border-radius: 5vmin;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
}
</style>
</head>
<body onload="slide()">
<div id="slider">
<img src="" alt="" />
</div>
<script>
var img = ["abhishek.png", "aish.png", "alok.png", "dayanand.png"];
console.log("img executed: ", img);
var i = 0;
console.log("i executed: ", i);
function slide() {
console.log("Slide executed");
// var div = document.querySelector("#slider");
var imageEl = document.querySelector("#slider img");
imageEl.style.content = `url(images/${img[i]})`;
console.log("div executed");
i++;
// if iterator = array length then do iterator = 0
if (img.length == i) {
i = 0;
}
setTimeout("slide()", 2000); //call slide() in every 2 second
}
</script>
</body>
</html>