Created
February 15, 2019 01:09
-
-
Save erik4github/290f8024830e1f1c9b5aa3202b1aea2d to your computer and use it in GitHub Desktop.
Animating URL bars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use history.replaceState() instead of history.pushState() in order to not spam browser history | |
var f = ['๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐']; | |
function loop() { | |
location.hash = f[Math.floor((Date.now()/100)%f.length)]; | |
setTimeout(loop, 50); | |
} | |
loop(); | |
// transitioning moon | |
var f = ['๐', '๐', '๐', '๐', '๐', '๐', '๐', '๐'], | |
d = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], | |
m = 0; | |
function loop() { | |
var s = '', x = 0; | |
if (!m) { | |
while (d[x] == 4) { | |
x ++; | |
} | |
if (x >= d.length) m = 1; | |
else { | |
d[x] ++; | |
} | |
} | |
else { | |
while (d[x] == 0) { | |
x ++; | |
} | |
if (x >= d.length) m = 0; | |
else { | |
d[x] ++; | |
if (d[x] == 8) d[x] = 0; | |
} | |
} | |
d.forEach(function (n) { | |
s += f[n]; | |
}); | |
location.hash = s; | |
setTimeout(loop, 50); | |
} | |
loop(); | |
//sinewave | |
function loop() { | |
var i, n, s = ''; | |
for (i = 0; i < 10; i++) { | |
n = Math.floor(Math.sin((Date.now()/200) + (i/2)) * 4) + 4; | |
s += String.fromCharCode(0x2581 + n); | |
} | |
window.location.hash = s; | |
setTimeout(loop, 50); | |
} | |
loop(); | |
// loadingbar | |
function loop() { | |
var s = '', | |
p; | |
p = Math.floor(((Math.sin(Date.now()/300)+1)/2) * 100); | |
while (p >= 8) { | |
s += 'โ'; | |
p -= 8; | |
} | |
s += ['โ ','โ','โ','โ','โ','โ','โ','โ'][p]; | |
location.hash = s; | |
setTimeout(loop, 50); | |
} | |
// progress bar | |
var video; | |
function formatTime(seconds) { | |
var minutes = Math.floor(seconds/60), | |
seconds = Math.floor(seconds - (minutes*60)); | |
return ('0'+minutes).substr(-2) + ':' + ('0'+seconds).substr(-2); | |
} | |
function renderProgressBar() { | |
var s = '', | |
l = 15, | |
p = Math.floor(video.currentTime / video.duration * (l-1)), | |
i; | |
for (i = 0; i < l; i ++) { | |
if (i == p) s +='โฏ'; | |
else if (i < p) s += 'โ'; | |
else s += 'โ'; | |
} | |
location.hash = 'โญ'+s+'โฎ'+formatTime(video.currentTime)+'โฑ'+formatTime(video.duration); | |
} | |
video = document.getElementById('video'); | |
video.addEventListener('timeupdate', renderProgressBar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment