-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·52 lines (46 loc) · 1.44 KB
/
script.js
File metadata and controls
executable file
·52 lines (46 loc) · 1.44 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
var winHeight = window.innerHeight;
var animDuration = winHeight * 4;
var animationData;
animationData = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': "https://raw.githubusercontent.com/dk38562/offshore/main/data.json",
'dataType': "json",
'success': function (data) {
json = data;
}
});
return json;
})();
var animData = {
container: document.getElementById('container'),
renderer: 'svg',
loop: false,
autoplay: false,
animationData: animationData,
};
var anim = bodymovin.loadAnimation(animData);
window.addEventListener('scroll', function() {
animatebodymovin(animDuration, anim);
});
function animatebodymovin(duration, animObject) {
var scrollPosition = window.scrollY;
var maxFrames = animObject.totalFrames;
var frame = (maxFrames / 100) * (scrollPosition / (duration / 100));
animObject.goToAndStop(frame, true);
}
function loadJSON(callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'https://raw.githubusercontent.com/dk38562/offshore/main/data.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState == 4 && xobj.status == "200") {
// Required use of an anonymous callback as .open will NOT return a value but simply returns undefined in asynchronous mode
callback(xobj.responseText);
console.log(xobj.responseText)
}
};
xobj.send(null);
}