forked from geelen/x-gif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
195 lines (178 loc) · 6.11 KB
/
index.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!doctype html>
<html>
<head>
<title><x-gif></title>
<script src="angular.min.js"></script>
<script src="dist/platform.js"></script>
<link rel="import" href="dist/x-gif.html">
<link rel="stylesheet" href="foundation.min.css"/>
<style>
body {
margin: 0;
background-color: #f9f9f9;
height: 100%;
text-align: center;
padding-bottom: 24px;
}
h3 {
margin-top: 2em;
}
body[unresolved] {
opacity: 0;
}
pre {
font-weight: bold;
margin-top: 8px;
}
.me {
height: 72px;
width: 72px;
border-radius: 50%;
box-shadow: 0 0 0 2px white, 0 0 0 3px black;
margin: 16px;
}
</style>
</head>
<body unresolved ng-app="x-gif-demo">
<div class="row">
<div class="column medium-9 medium-centered large-8">
<header>
<h1><x-gif></h1>
<h4>The GIF tag the internet deserves</h4>
<h6><a href="https://github.com/geelen/x-gif" target="_blank">View source on GitHub</a></h6>
</header>
<hr/>
<nav>
<dl class="sub-nav">
<dt>Examples:</dt>
<dd ng-repeat="url in gifs" ng-class="{active: gif.url == url}"><a ng-href="#{{ url }}"> {{ $index + 1 }} </a>
</dd>
</dl>
<label>
Or choose your own. Be sure to choose a server with permissive CORS headers, e.g. imgur
<input type="text" ng-model="gif.url"/>
</label>
</nav>
<h3>Normal playback</h3>
<p class="small">Something not look right? <a href="https://github.com/geelen/x-gif/issues" target="_blank">Post an issue on GitHub</a> with the URL of the image</p>
<figure>
<x-gif ng-src="{{ trustedUrl() }}"></x-gif>
<figcaption>
<pre><x-gif src="{{ trustedUrl() }}"></x-gif></pre>
</figcaption>
</figure>
<h3>Ping-pong</h3>
<figure>
<x-gif ng-src="{{ trustedUrl() }}" ping-pong></x-gif>
<figcaption>
<pre><x-gif src="{{ trustedUrl() }}" ping-pong></x-gif></pre>
</figcaption>
</figure>
<h3>Speed</h3>
<figure>
<label>
<input type="range" min="0.1" max="5" step="0.1" ng-model="gif.speed"/> {{ gif.speed }}
</label>
<x-gif ng-src="{{ trustedUrl() }}" speed="{{ gif.speed }}"></x-gif>
<figcaption>
<pre><x-gif src="{{ trustedUrl() }}" speed="{{ gif.speed }}"></x-gif></pre>
</figcaption>
</figure>
<h3>Synced to Audio</h3>
<figure>
<div ng-show="gif.metadata">
<audio src="demos/cc_audio/encom_part_ii.ogg" controls preload></audio>
<p>Playback speed: {{ gif.playbackRate | number:1 }} <a href ng-click="changeSpeed(0.1)">+</a> <a href
ng-click="changeSpeed(-0.1)">-</a>
</p>
</div>
<div ng-hide="gif.metadata">Loading beat data...</div>
<x-gif id="synced" ng-src="{{ trustedUrl() }}" sync></x-gif>
<figcaption>
<pre><x-gif src="{{ trustedUrl() }}" synced></x-gif></pre>
<p>
Audio: Encom Part II by Daft Punk. CC0 1.0 Universal.
<br/>
Source:
<a href="https://archive.org/details/DaftPunkTronLegacyEncomPartIi" target="_blank">Archive.org</a>
<br/>
Beat metadata provided by <a href="http://echonest.com/">Echo Nest</a>
</p>
<h5><a href="demos/audio.html">See a full screen demo</a></h5>
</figcaption>
</figure>
<hr/>
<footer>
<h5>Made with <3 by</h5>
<img class="me" src="http://i.imgur.com/x577Tga.jpg" alt=""/>
<br/>
<a target="_blank" href="https://twitter.com/glenmaddern">@glenmaddern</a>
</footer>
</div>
</div>
<script type="text/javascript" charset="utf-8">
angular.module('x-gif-demo', [])
.run(function ($rootScope, $sce, $location, $http) {
$rootScope.gifs = [
"http://i.imgur.com/YlxOOI7.gif",
"http://i.imgur.com/m25uYzq.gif",
"http://i.imgur.com/KcL1asA.gif",
"http://i.imgur.com/RY2vTBQ.gif",
"http://i.imgur.com/iKXH4E2.gif",
"http://i.imgur.com/5KSc0px.gif",
"http://i.imgur.com/ifR7csn.gif"
];
$rootScope.gif = {
url: $rootScope.gifs[Math.floor(Math.random() * $rootScope.gifs.length)],
speed: 2,
playbackRate: 1
};
$rootScope.changeSpeed = function (delta) {
audio.playbackRate = Math.max(0.5, audio.playbackRate + delta);
$rootScope.gif.playbackRate = audio.playbackRate;
}
$http.get('demos/cc_audio/encom_part_ii.json').then(function (response) {
$rootScope.gif.metadata = response.data;
})
$rootScope.trustedUrl = function () {
return $sce.trustAsResourceUrl($rootScope.gif.url);
}
$rootScope.loc = $location;
$rootScope.$watch('loc.path()', function (e) {
if (e) $rootScope.gif.url = e.slice(1);
})
$rootScope.$watch('gif.url', function (e) {
if (e) $rootScope.loc.path(e);
})
var synchOffset = -0.1,
audio = document.querySelector('audio'),
xGif = document.querySelector('#synced');
audio.addEventListener('playing', function () {
var beats = $rootScope.gif.metadata.response.track.analysis.beats,
beatIndex = 0;
while (beats[0].start > 0) {
beats.unshift({
start: beats[0].start - beats[0].duration,
duration: beats[0].duration,
confidence: 0
})
}
var animationLoop = function () {
requestAnimationFrame(animationLoop);
if (beats.length > beatIndex) {
var currentTime = audio.currentTime + synchOffset;
while (beatIndex < beats.length && currentTime > beats[beatIndex].start) {
beatIndex++;
}
var beat = beats[beatIndex - 1];
var sinceLastBeat = currentTime - beat.start,
beatFraction = sinceLastBeat / beat.duration;
xGif.clock(beatIndex, beat.duration * 1000 / audio.playbackRate, beatFraction);
}
}
animationLoop();
});
});
</script>
</body>
</html>