File size: 2,562 Bytes
c3d5f0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
<head>
  <style>body {
 background-color: #EBF2F5;
 overflow: hidden;
 text-align: center;
}

body,
html {
 height: 100%;
 width: 100%;
 margin: 0;
 padding: 0;
}

#animationWindow {
 width: 100%;
 height: 100%;
}</style>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/4.10.1/bodymovin.min.js"></script>
</head>
<body>
  <div id="animationWindow">
</div>
  <script>var select = function(s) {
    return document.querySelector(s);
  },
  selectAll = function(s) {
    return document.querySelectorAll(s);
  }, 
  animationWindow = select('#animationWindow'),    
    animData = {
		wrapper: animationWindow,
		animType: 'svg',
		loop: true,
		prerender: true,
		autoplay: true,
		path: 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/35984/play_fill_loader.json',
  rendererSettings: {
    //context: canvasContext, // the canvas context
    //scaleMode: 'noScale',
    //clearCanvas: false,
    //progressiveLoad: false, // Boolean, only svg renderer, loads dom elements when needed. Might speed up initialization for large number of elements.
    //hideOnTransparent: true //Boolean, only svg renderer, hides elements when opacity reaches 0 (defaults to true)
  }   
	}, anim;

anim = bodymovin.loadAnimation(animData);
anim.setSpeed(1);
anim.addEventListener('DOMLoaded', onDOMLoaded);

function onDOMLoaded(e){
  // Interactive scrub behavior removed.
  // Provide an autonomous back-and-forth scrub so the animation remains dynamic without user input.
  var totalFrames = 0;
  try {
    if (typeof anim.totalFrames !== 'undefined') totalFrames = anim.totalFrames;
    else if (typeof anim.getDuration === 'function') totalFrames = Math.round(anim.getDuration(true));
  } catch (err) {
    totalFrames = 0;
  }

  // If we can't determine frames, fall back to normal playback.
  if (!totalFrames) {
    if (typeof anim.play === 'function') anim.play();
    return;
  }

  var frame = 0;
  var direction = 1; // 1 = forward, -1 = backward
  var framesPerTick = Math.max(1, Math.round(totalFrames / 300)); // control speed relative to length

  function tick() {
    frame += direction * framesPerTick;
    if (frame >= totalFrames) {
      frame = totalFrames;
      direction = -1;
    } else if (frame <= 0) {
      frame = 0;
      direction = 1;
    }
    // goToAndStop expects (value, isFrame)
    if (typeof anim.goToAndStop === 'function') {
      anim.goToAndStop(frame, true);
    }
    requestAnimationFrame(tick);
  }

  // Start autonomous scrub loop
  requestAnimationFrame(tick);
}
</script>
</body>
</html>