-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (86 loc) · 3.07 KB
/
index.js
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
const reviews = [
{
id: 1,
name: "Kavya",
job: "College Student",
img:
"https://cdn.pixabay.com/photo/2018/11/13/21/43/instagram-3814049__340.png",
text:
"I have been studying languages for years, and I can confidently say that this language learningwebsite is one of the best resources I have come across."
},
{
id: 2,
name: "Ishan",
job: "Web Developer",
img:
"https://cdn.pixabay.com/photo/2018/11/13/21/43/instagram-3814049__340.png",
text:
"I have been studying languages for years, and I can confidently say that this language learningwebsite is one of the best resources I have come across."
},
{
id: 3,
name: "Krishna",
job: "Reviewer ",
img:
"https://cdn.pixabay.com/photo/2018/11/13/21/43/instagram-3814049__340.png",
text:
"I have been studying languages for years, and I can confidently say that this language learningwebsite is one of the best resources I have come across."
},
{
id: 4,
name: "Karan Goyal",
job: "Senior College Student",
img:
"https://cdn.pixabay.com/photo/2018/11/13/21/43/instagram-3814049__340.png",
text:
"I have been studying languages for years, and I can confidently say that this language learningwebsite is one of the best resources I have come across."
}
];
const img = document.getElementById("person-img");
const author = document.getElementById("author");
const job = document.getElementById("job");
const info = document.getElementById("info");
const prevBtn = document.querySelector(".prev-btn");
const nextBtn = document.querySelector(".next-btn");
let currentItem = 0;
window.addEventListener("DOMContentLoaded", () => {
const item = reviews[currentItem];
img.src = item.img;
author.textContent = item.name;
job.textContent = item.job;
info.textContent = item.text;
});
function showPerson(person) {
const item = reviews[person];
img.src = item.img;
author.textContent = item.name;
job.textContent = item.job;
info.textContent = item.text;
}
nextBtn.addEventListener("click", () => {
currentItem++;
if (currentItem > reviews.length - 1) {
currentItem = 0;
}
showPerson(currentItem);
});
prevBtn.addEventListener("click", () => {
currentItem--;
if (currentItem < 0) {
currentItem = reviews.length - 1;
}
showPerson(currentItem);
});
let mybutton = document.getElementById("myBtn");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
function topFunction() {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
}