-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam1.js
134 lines (124 loc) · 4.07 KB
/
team1.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
var sliderTeam = (function (document, $) {
"use strict";
var $sliderTeams = $(".slider--teams"),
$list = $("#list"),
$listItems = $("#list li"),
$nItems = $listItems.length,
$nView = 3,
autoSlider,
$current = 0,
$isAuto = true,
$acAuto = 1500,
_init = function () {
_initWidth();
_eventInit();
},
_initWidth = function () {
$list.css({
"margin-left": Math.floor(100 / $nView) + "%",
width: Math.floor(100 * ($nItems / $nView)) + "%",
});
$listItems.css("width", 100 / $nItems + "%");
$sliderTeams.velocity(
{ opacity: 1 },
{ display: "block" },
{ delay: 1000 }
);
},
_eventInit = function () {
window.requestAnimFrame = (function () {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback, element) {
window.setTimeout(callback, 1000 / 60);
}
);
})();
window.requestInterval = function (fn, delay) {
if (
!window.requestAnimationFrame &&
!window.webkitRequestAnimationFrame &&
!window.mozRequestAnimationFrame &&
!window.oRequestAnimationFrame &&
!window.msRequestAnimationFrame
)
return window.setInterval(fn, delay);
var start = new Date().getTime(),
handle = new Object();
function loop() {
var current = new Date().getTime(),
delta = current - start;
if (delta >= delay) {
fn.call();
start = new Date().getTime();
}
handle.value = requestAnimFrame(loop);
}
handle.value = requestAnimFrame(loop);
return handle;
};
window.clearRequestInterval = function (handle) {
window.cancelAnimationFrame
? window.cancelAnimationFrame(handle.value)
: window.webkitCancelRequestAnimationFrame
? window.webkitCancelRequestAnimationFrame(handle.value)
: window.mozCancelRequestAnimationFrame
? window.mozCancelRequestAnimationFrame(handle.value)
: window.oCancelRequestAnimationFrame
? window.oCancelRequestAnimationFrame(handle.value)
: window.msCancelRequestAnimationFrame
? msCancelRequestAnimationFrame(handle.value)
: clearInterval(handle);
};
$.each($listItems, function (i) {
var $this = $(this);
$this.on("touchstart click", function (e) {
e.preventDefault();
_stopMove(i);
_moveIt($this, i);
});
});
autoSlider = requestInterval(_autoMove, $acAuto);
},
_moveIt = function (obj, x) {
var n = x;
obj.find("figure").addClass("active");
$listItems.not(obj).find("figure").removeClass("active");
$list.velocity(
{
translateX: Math.floor(-(100 / $nItems) * n) + "%",
translateZ: 0,
},
{
duration: 1000,
easing: [400, 26],
queue: false,
}
);
},
_autoMove = function (currentSlide) {
if ($isAuto) {
$current = ~~(($current + 1) % $nItems);
} else {
$current = currentSlide;
}
console.log($current);
_moveIt($listItems.eq($current), $current);
},
_stopMove = function (x) {
clearRequestInterval(autoSlider);
$isAuto = false;
_autoMove(x);
};
return {
init: _init,
};
})(document, jQuery);
$(window).load(function () {
"use strict";
sliderTeam.init();
});