-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscrollux.js
More file actions
474 lines (324 loc) · 11.6 KB
/
scrollux.js
File metadata and controls
474 lines (324 loc) · 11.6 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
class Scrollux {
constructor(custom){
// DOM Elements
this.$body = $('body');
this.$section = $('section');
this.$divanchor = null;
this.navWidth = $(window).width();
this.navHeight = $(window).height();
this.$navigator = null;
this.keysPx = null;
this.currentPage = null;
this.scrollbar = null;
this.counter = 1;
// Arrays
this.anchors = [];
// Settings which the developper can customize
this.defaults = {
overflowY : "hidden",
overflowX : "hidden",
ringListColor : "#FFF",
ringListSize : "9px",
ringActualSessionColor : "#FFF",
ringHoverColor : "#FFF",
setTimeAnimation : 1000,
footer : false,
footerSize : "500px"
};
this.settings = $.extend({}, this.defaults, custom);
// Initialization
this.init();
}
init(){
var i = this.$section.length;
if (i > 0) {
var settings = this.settings;
this.navigatorClient();
this.keysSettingsPx();
this.findSACA(i, settings.footer);
this.createAside(i);
this.displayCSS(settings.overflowY, settings.overflowX, settings.ringListColor, settings.ringListSize, settings.footerSize);
this.$divanchor = $('.divanchor');
this.hoverList(1, settings.ringActualSessionColor);
this.fcurrentPage(i);
this.keymap(i, settings.setTimeAnimation);
this.scrollWinY(i, settings.setTimeAnimation);
this.anchorClick();
this.mouseHover(settings.ringHoverColor, settings.ringActualSessionColor);
} else {
console.log("You don't have any DOM section in your body !")
}
}
// # 1) Find sections, addClass and create anchor for each
findSACA(i, footer){
// Search sections
var finder = $('body').find('section');
var a = 1;
if (i >= a) {
for (var find of finder) {
// Add class for each section
if (i >= a) {
$(find).addClass('page-' + a);
$(find).attr('id', 'page-' + a);
// Create a anchor for each section
var anchor = "<a href=\"#page-"+ a +"\">"
+"<div id=\"divpage-"+ a +"\" class=\"divanchor \"></div>"
+ "</a>";
this.anchors.push(anchor);
a += 1;
}
}
if (footer == true) {
finder.last().addClass('footer');
}
} else {
console.log("You don't have any DOM section in your body !")
}
}
// # 2) Display responsive CSS
displayCSS(overflowY, overflowX, ringListColor, ringListSize, footerSize){
var body = this.$body;
var section = this.$section;
var aside = $('#aside-scroll');
var ul = $('#ul-scroll');
var li = $('.asidelist');
var div = $('.divanchor');
var asideHeight = aside.height();
body.css({
"margin" : "0px",
"overflow-y" : overflowY,
"overflow-x" : overflowX
});
section.css({
"width" : "100vw",
"height" : "100vh",
"position" : "relative"
});
$('.footer').css({
"height" : footerSize
});
aside.css({
"position" : "fixed",
"top" : "calc(50% - ("+ asideHeight +"px / 2))",
"right" : "48px",
"width" : "auto",
"height" : "auto",
"z-index" : "9999"
});
ul.css({
"list-style-type" : "none",
"display" : "flex",
"flex-direction" : "column"
});
li.css({
"margin-bottom" : "20px"
});
div.css({
"width" : ringListSize,
"height" : ringListSize,
"border" : "2px solid " + ringListColor,
"border-radius" : "50%",
"cursor" : "pointer",
"background-color" : "rgba(255, 255, 255, 0)"
});
}
// # 3) Create a list for DOM aside
createAside(i){
var list = "<aside id=\"aside-scroll\"><ul id=\"ul-scroll\">";
for ( var a = 0 ; a < i ; a++ ) {
list += "<li class=\"asidelist\">" + this.anchors[a] + "</li>";
}
list += "</ul></aside>";
this.$body.append(list);
}
// # 4) Current Page Settings
fcurrentPage(i){
var i = i;
var h = this.navHeight;
var app = this;
$(window).on('scroll' ,function(){
app.$scrollbar = $(window).scrollTop();
var scrollbar = app.$scrollbar;
for (var y = 0 ; y < i ; y++) {
var min = (h * (y + 1));
var max = (h * (y + 2));
if (scrollbar <= h) {
app.currentPage = y + 1;
break;
}
if (scrollbar > min && scrollbar < max){
app.currentPage = y + 2;
break;
}
}
});
}
// # 5) Keys Settings
keymap(i, setTimeAnimation){
var i = i;
var app = this;
var flag = true; // bool for animation
$(document).keydown(function(e){
if (flag == false) {
return;
}
if (e.keyCode != 40 || e.keyCode != 38) {
event.preventDefault();
flag = true;
}
flag = false;
// Down
if (e.keyCode == 40) {
if (app.counter != i) {
app.counter += 1
}
var counter = app.counter;
if (counter < (i + 1)) {
app.currentPage = app.counter;
app.hoverList(counter);
$('html, body').animate({
scrollTop : $(".page-" + app.counter).offset().top
}, setTimeAnimation, function(){
flag = true;
});
}
} else if (e.keyCode == 38) {
if (app.counter != 1) {
app.counter -= 1
}
var counter = app.counter;
if (counter > 0) {
app.currentPage = app.counter;
app.hoverList(counter);
$('html, body').animate({
scrollTop : $(".page-" + app.counter).offset().top
}, setTimeAnimation, function(){
flag = true;
});
}
}
});
}
// # 6) Scroll event
scrollWinY(i, setTimeAnimation){
var i = i;
var app = this;
var flag = true; // bool for animation
$(document).bind('DOMMouseScroll mousewheel MozMousePixelScroll', function(e){
if (flag == false) {
return;
}
//descente neg //montee pos
var wheelEvent = event.wheelDeltaY;
flag = false;
if (wheelEvent < 0) {
if (app.counter != i) {
app.counter += 1
}
var counter = app.counter;
if (counter < (i + 1)) {
app.currentPage = app.counter;
app.hoverList(counter);
$('html, body').animate({
scrollTop : $(".page-" + app.counter).offset().top
}, setTimeAnimation, function(){
flag = true;
});
}
} else {
if (app.counter != 1) {
app.counter -= 1
}
var counter = app.counter;
if (counter > 0) {
app.currentPage = app.counter;
app.hoverList(counter);
$('html, body').animate({
scrollTop : $(".page-" + app.counter).offset().top
}, setTimeAnimation, function(){
flag = true;
});
}
}
});
}
// # 7) Navigator detection
navigatorClient(){
if(navigator.userAgent.indexOf("Firefox") != -1 ) {
this.$navigator = "Firefox";
} else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
this.$navigator = "IE";
} else {
this.$navigator = "Default";
}
}
// # 8) Keys px
keysSettingsPx(){
if (this.$navigator == 'Default') {
this.keysPx = 40;
} if (this.$navigator == 'Firefox') {
this.keysPx = 48;
}
}
// 9) Add color on eventlist on client page.
hoverList(ctp){
var divanchor = this.$divanchor;
if (divanchor.hasClass('actual-Session')) {
$('.actual-Session').css({
"background-color" : "rgba(255, 255, 255, 0)"
});
divanchor.removeClass('actual-Session');
}
$('#divpage-' + ctp).addClass('actual-Session');
$('.actual-Session').css({
"background-color" : this.settings.ringActualSessionColor
});
}
// # 10) Anchor on click
anchorClick(){
var app = this;
var anchor = $('#ul-scroll').find('a');
anchor.on('click', function(){
var idom = $(this).children().attr('id');
var ctp = idom.replace("divpage-", "");
app.counter = parseInt(ctp);
app.currentPage = app.counter;
app.hoverList(app.counter);
console.log(app.hoverList(app.counter));
// var divanchor = app.$divanchor;
// if (divanchor.hasClass('actual-Session')) {
// $('.actual-Session').css({
// "background-color" : "rgba(255, 255, 255, 0)"
// });
// divanchor.removeClass('actual-Session');
// }
// $('#divpage-' + app.counter).addClass('actual-Session');
// $('.actual-Session').css({
// "background-color" : "white"
// });
});
}
// # 11) Display Css for mouse hoverlist
mouseHover(ringHoverColor, ringActualSessionColor){
var app = this;
var div = $('.divanchor');
var self = null;
div.hover(function(){
self = $(this);
self.css({
"background-color" : ringHoverColor
});
}, function(){
if (self.hasClass('actual-Session')) {
self.css({
"background-color" : ringActualSessionColor
});
return;
} else {
self.css({
"background-color" : "rgba(255, 255, 255, 0)"
});
}
});
}
}