-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
81 lines (77 loc) · 2.05 KB
/
script.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
// button variable for controlling onclick() event of menubar in mobile devices.
const bt = document.querySelector("#nav");
const menu = document.querySelector("#menu");
bt.onclick = open;
function open()
{
menu.style.display = "block";
bt.onclick = close;
}
function close()
{
bt.onclick = open;
menu.style.display = "none";
}
// Variables to control display of the three images of a particular product/item.
const one = document.querySelector(".one");
const two = document.querySelector(".two");
const three = document.querySelector(".three");
// button variables for controlling onclick() event on previous and next buttons to control
// slideshow of images.
const bt1 = document.querySelector("#prev");
const bt2 = document.querySelector("#next");
bt1.onclick = prev;
bt2.onclick = next;
let current = 1;
// Function to move between images backwards in a cycle
function prev()
{
current--;
if(current==0)
{
// Display the required image based on value of current
// and hide the others.
current = 3;
three.style.display = "block";
one.style.display = "none";
two.style.display = "none";
}
if(current==1)
{
one.style.display = "block";
two.style.display = "none";
three.style.display = "none";
}
if(current==2)
{
one.style.display = "none";
two.style.display = "block";
three.style.display = "none";
}
}
// Function to move between images forward in a cycle
function next()
{
current++;
if(current==4)
{
// Display the required image based on value of current
// and hide the others.
current = 1;
three.style.display = "none";
one.style.display = "block";
two.style.display = "none";
}
if(current==2)
{
one.style.display = "none";
two.style.display = "block";
three.style.display = "none";
}
if(current==3)
{
one.style.display = "none";
two.style.display = "none";
three.style.display = "block";
}
}