-
Notifications
You must be signed in to change notification settings - Fork 0
/
carousel.js
111 lines (99 loc) · 3.5 KB
/
carousel.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
jQuery(document).ready(function($) {
//navbar hamburger menu
$(document).ready( function(){
$('body').on('click', '.hamburger', function() {
$('#myNav').animate({
display: 'block',
height: '100%'
}, 'fast');
});
$('body').on('click', '.closebtn', function(){
$('#myNav').animate({
display: 'none',
height: '0%'
}, 'fast');
});
});
var sliders = [];
var delay = 1000;
var timerId;
var remaining;
var start;
var current_playing;
// restore user slider img and title or descriptions
$("#rotate-slider").find("img").each(function() {
this.className += " slider-hide";
sliders.push({html: this})
});
// initialize the siliders
function slider_init() {
$("#rotate-slider").css('display', 'block');
$("#rotate-slider").append("<div id='slider-btn'><a class='prev-btn'><i class='fa fa-arrow-left' aria-hidden='true'></i> <span class='hidden-xs'>PREV</span<</a><a class='next-btn'><span class='hidden-xs'>NEXT</span> <i class='fa fa-arrow-right' aria-hidden='true'></i></a></div>")
slider_display(sliders, 0);
slider_loop(sliders, -1, delay);
}
// display 5 img at a time
function slider_display(A, i) {
if (i < 0) {
i = A.length -1;
}
current_playing = i;
// mute the one img before
A[(i + A.length + 3) % A.length].html.className += " slider-hide";
// display 5 img after the muted one
A[(i + A.length) % A.length].html.className = "slider-middle";
A[(i + A.length - 1) % A.length].html.className = "slider-left-1";
// A[(i + A.length - 2) % A.length].html.className = "slider-left-2";
A[(i + A.length + 1) % A.length].html.className = "slider-right-1";
// A[(i + A.length + 2) % A.length].html.className = "slider-right-2";
}
// slider
function slider_loop(A, i, remaining) {
start = new Date();
if (i < 0) {
i = A.length -1;
}
}
$("body").hover(function() {
window.clearTimeout(timerId);
remaining = delay - (new Date() - start);
$("#slider-btn .prev-btn").click(function() {
current_playing++;
slider_display(sliders, current_playing);
});
$("#slider-btn .next-btn").click(function() {
current_playing--;
slider_display(sliders, current_playing);
});
}, function() {
slider_loop(sliders, current_playing, remaining);
$("#slider-btn .prev-btn").unbind("click");
$("#slider-btn .next-btn").unbind("click");
});
$('body').mousemove(function(event) {
if (event.pageX < 400) {
$('.prev-btn').show();
$('.next-btn').hide();
} else if ( event.pageX > 800) {
$('.prev-btn').hide();
$('.next-btn').show();
} else {
$('.prev-btn').hide();
$('.next-btn').hide();
}
});
$(window).on('wheel', function(e) {
e.preventDefault();
if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
//scroll nagore
current_playing++;
slider_display(sliders, current_playing);
}
else{
//scroll nadole
current_playing--;
slider_display(sliders, current_playing);
}
});
slider_init();
});