-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3D-Book.js
100 lines (81 loc) · 2.52 KB
/
3D-Book.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
99
100
//turn page when click next or prev button
const pageTurnBtn = document.querySelectorAll('.nextprev-btn');
pageTurnBtn.forEach((el, index) => {
el.onclick = () => {
const pageTurnId = el.getAttribute('data-page');
const pageTurn = document.getElementById(pageTurnId);
if (pageTurn.classList.contains('turn')){
pageTurn.classList.remove('turn');
setTimeout(() => {
pageTurn.style.zIndex = 20 - index;
}, 500)
}
else{
pageTurn.classList.add('turn');
setTimeout(() => {
pageTurn.style.zIndex = 20 + index;
}, 500)
}
}
})
// contact me butten when click
const pages = document.querySelectorAll('.book-page.page-right');
const contactMeBtn = document.querySelector('.btn.contact-me');
contactMeBtn.onclick = () => {
pages.forEach((page, index) => {
setTimeout(() => {
page.classList.add('turn');
setTimeout(() => {
page.style.zIndex = 20 + index;
}, 500)
}, (index + 1) * 200 + 100)
})
}
// create reverse index function
let totalPages = pages.length;
let pageNumber = 0;
function reverseIndex() {
pageNumber--;
if (pageNumber < 0) {
pageNumber = totalPages - 1;
}
}
//back profile butten when click\
const backProfileBtn = document.querySelector('.back-profile');
backProfileBtn.onclick = () => {
pages.forEach((_, index) => {
setTimeout(() => {
reverseIndex();
pages[pageNumber].classList.remove('turn');
setTimeout(() => {
reverseIndex();
pages[pageNumber].style.zIndex = 10 + index;
}, 500)
}, (index + 1) * 200 + 100)
})
}
//opening animation
const coverRight = document.querySelector('.cover.cover-right');
const pageLeft = document.querySelector('.book-page.page-left');
//opening animation (cover right animation)
setTimeout(() => {
coverRight.classList.add('turn');
}, 2100)
setTimeout(() => {
coverRight.style.zIndex = -1;
}, 2800)
//opening animation (page left or profile page animation)
setTimeout(() => {
pageLeft.style.zIndex = 20;
}, 3200)
//opening animation (all page right animation)
pages.forEach((_, index) => {
setTimeout(() => {
reverseIndex();
pages[pageNumber].classList.remove('turn');
setTimeout(() => {
reverseIndex();
pages[pageNumber].style.zIndex = 10 + index;
}, 500)
}, (index + 1) * 200 + 2100)
})