-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (50 loc) · 1.33 KB
/
script.js
File metadata and controls
65 lines (50 loc) · 1.33 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
/* Noel Delgado | @pixelia_me */
/*
*** full attribution ***
- Original infographic
- http://www.fremtidensbusiness.dk/wp-content/uploads/2015/04/evolution.png
*/
var CONFIG = {
duration: 1000,
easing: 'elastic-out',
rotation: 'none',
};
var phonesInfo = [].slice.call(document.getElementsByTagName('g'), 0).map(function(el) {
return {
id : el.getAttribute('id'),
easing : el.getAttribute('data-easing') || CONFIG.easing,
duration : el.getAttribute('data-duration') || CONFIG.duration
};
});
var phonesLen = (phonesInfo.length - 1);
var timelineElement = document.querySelector('.timeline-list');
var moveTimelinePxs = 69;
var now, delta;
var interval = 1500 * 1;
var then = +new Date();
var index = 0;
var M = new SVGMorpheus('#mobiltelefonens', CONFIG);
/* ~~~~~~~ */
update();
loop();
function update() {
var p = phonesInfo[index++];
var x = (((index - 1) * moveTimelinePxs) * -1);
M.to(p.id, {
easing: p.easing,
duration: p.duration
});
timelineElement.style.webkitTransform = 'translateX(' + x + 'px)';
timelineElement.style.transform = 'translateX(' + x + 'px)';
if (index > phonesLen) index = 0;
p = x = null;
}
function loop() {
requestAnimationFrame(loop);
now = +new Date();
delta = now - then;
if (delta > interval) {
then = now - (delta % interval);
update();
}
}