-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainpage.js
145 lines (125 loc) · 5.1 KB
/
mainpage.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
let book = [ // Livre représenté sous forme d'une liste, chaque élément représente une page
{ display: [".background_img"], animation: 'book_open_2.gif', arrows: "none", infinite_anim: false },
{ display: [".content", ".features", ".feature",], animation: { left: 'book_close.gif', right: 'page_turn.gif' }, arrows: "both" },
{ display: [".features", '.feature_2', ".feature_3"], animation: { left: 'page_unturn.gif', right: 'page_turn.gif' }, arrows: "both" },
{ display: ["header", "footer"], animation: { left: 'page_unturn.gif' }, infinite_anim: false, arrows: "left", background: "home_background.png" },
//{ display: [""], animation: '' },
]
let mobile_book = [
{ display: [".background_img"], animation: 'book_open_2.gif', arrows: "none", infinite_anim: false },
{ display: [".content"], animation: { left: 'book_close.gif', right: 'page_turn.gif' }, background: "demi_page_left.png", infinite_anim: false, arrows: "both" },
{ display: [".features", ".feature",], animation: { left: 'page_turn.gif', right: 'page_turn.gif' }, background: "demi_page_right.png", infinite_anim: false, arrows: "both" },
{ display: [".features", '.feature_2'], animation: { left: 'page_turn.gif', right: 'page_turn.gif' }, background: "demi_page_left.png", infinite_anim: false, arrows: "both" },
{ display: [".features", ".feature_3"], animation: { left: 'page_turn.gif', right: 'page_turn.gif' }, background: "demi_page_right.png", infinite_anim: false, arrows: "both" },
{ display: ["header"], animation: { left: 'page_turn.gif', right: 'page_turn.gif' }, background: "demi_page_home_background.png", infinite_anim: false, arrows: "both" },
{ display: ["footer"], animation: { left: 'page_turn.gif' }, background: "demi_page_right.png", infinite_anim: false, arrows: "left" },
]
let all_elements = ["#left_arrow", "#right_arrow"]
function get_all_elements() {
for (let element of book) {
for (let elt of element.display) {
if (all_elements.includes(elt)) continue
all_elements.push(elt)
}
}
}
function display(value, array) {
for (let elt of array) {
let element
if (elt.includes('#')) {
elt = elt.slice(1)
element = document.getElementById(elt)
}
else {
element = document.querySelector(elt)
}
element.style.display = value
}
}
var page_number = 0
function turn_page(sens) {
let page = book[page_number]
let origin_num = page_number
if (sens == "left") {
page_number -= 1
} else {
page_number += 1
}
if (screen.width <= 768) {
if (page_number < 0 || page_number > mobile_book.length) {
page_number = origin_num
return "bruh"
}
page = mobile_book[origin_num]
}
else {
if (page_number < 0 || page_number > book.length) {
page_number = origin_num
return "bruh"
}
}
//GIF SRC
let animation_src = ""
if (typeof page.animation != "string") {
animation_src = page.animation[sens]
} else {
animation_src = page.animation
}
//DISPLAY NONE ALL
display("none", all_elements)
//GIF APPEND
let gifImage = document.createElement('img')
gifImage.style.display = "block"
gifImage.style.width = "100%"
gifImage.style.height = "100%"
gifImage.src = animation_src;
gifImage.autoplay = true;
let gif_container = document.getElementById('gif_container');
gif_container.innerHTML = '';
gif_container.style.display = "block";
gif_container.appendChild(gifImage);
//POUF
setTimeout(() => {
let new_page = book[page_number]
if (screen.width <= 768) {
new_page = mobile_book[page_number]
}
if (new_page.infinite_anim != undefined && new_page.infinite_anim == false) {
if (new_page.background != undefined) {
gifImage.src = new_page.background
}
else {
gifImage.style.display = "none"
gif_container.style.display = "none"
}
}
if (new_page.arrows != "none") {
if (new_page.arrows == "left" || new_page.arrows == "both") {
left_arrow.style.display = "block"
}
if (new_page.arrows == "right" || new_page.arrows == "both") {
right_arrow.style.display = "block"
}
}
display("block", new_page.display)
}, 250);
}
function init_display() {
get_all_elements()
display("none", all_elements)
let gif_container = document.getElementById('gif_container');
gif_container.style.display = "none"
let new_page = book[page_number]
if (screen.width <= 768) {
new_page = mobile_book[page_number]
}
if (new_page.arrows != "none") {
if (new_page.arrows == "left" || new_page.arrows == "both") {
left_arrow.style.display = "block"
}
if (new_page.arrows == "right" || new_page.arrows == "both") {
right_arrow.style.display = "block"
}
}
display("block", new_page.display)
}