-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarousel.html
106 lines (83 loc) · 2.91 KB
/
carousel.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
102
103
104
105
106
<!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 rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="/style/carousel.css">
<link rel="stylesheet" href="style/normalize.css">
</head>
<body>
<div id="img-carousel">
<i class="fas fa-chevron-left"></i>
<a href="" id="carousel-link">
<img src="" alt="" id="carousel-img">
</a>
<i class="fas fa-chevron-right"></i>
</div>
</body>
</html>
<script>
let images = [
"carousel_src/Banner__1639034174307.jpg",
"carousel_src/2__1635260988274.jpg",
"carousel_src/3__1635261036491.jpg",
"carousel_src/4__1635261083350.jpg"
];
let urls = [
"https://www.upgrad.com/",
"https://www.upgrad.com/mba-course/?utm_source=ORGANIC&utm_medium=ALL&utm_campaign=IND_BRD_WEB_ALL_homepagebanner_ALL_ALL_ALL_FF2MBA_ALL",
"https://www.upgrad.com/data-science-course/?utm_source=ORGANIC&utm_medium=ALL&utm_campaign=IND_BRD_WEB_ALL_homepagebanner_ALL_ALL_ALL_FF2MBA_ALL",
"https://www.upgrad.com/executive-mba-ssbm/?utm_source=ORGANIC&utm_medium=ALL&utm_campaign=IND_BRD_WEB_ALL_homepagebanner_ALL_ALL_ALL_FF2MBA_ALL"
];
let index = 1;
setInterval(()=>{
index = (index + 1)%images.length;
carousel_img(images,urls,index)
},6000);
carousel_img(images,urls,0);
function carousel_img(images,urls,index) {
let a = document.getElementById("carousel-link");
a.setAttribute("href",urls[index]);
let img = document.getElementById("carousel-img");
img.setAttribute("src",images[index]);
}
let left_arrow = document.querySelectorAll("#img-carousel i")[0];
let right_arrow = document.querySelectorAll("#img-carousel i")[1];
left_arrow.addEventListener("click",()=>{
if(index==0) {
index=images.length-1;
} else{
index--;
}
carousel_img(images,urls,index);
})
right_arrow.addEventListener("click",()=>{
index = (index +1 )%images.length;
carousel_img(images,urls,index);
})
</script>
<!--
// carousel starts
document.getElementById("img-carousel").innerHTML = carousel();
setInterval(()=>{
index = (index + 1)%images.length;
carousel_img(index)
},6000);
carousel_img(images,urls,0);
let left_arrow = document.querySelectorAll("#img-carousel i")[0];
let right_arrow = document.querySelectorAll("#img-carousel i")[1];
left_arrow.addEventListener("click",()=>{
if(index==0) {
index=images.length-1;
} else{
index--;
}
carousel_img(images,urls,index);
})
right_arrow.addEventListener("click",()=>{
index = (index +1 )%images.length;
carousel_img(images,urls,index);
}) -->