Skip to content

Instantly share code, notes, and snippets.

@erik4github
Created February 15, 2019 01:09
Show Gist options
  • Save erik4github/290f8024830e1f1c9b5aa3202b1aea2d to your computer and use it in GitHub Desktop.
Save erik4github/290f8024830e1f1c9b5aa3202b1aea2d to your computer and use it in GitHub Desktop.
Animating URL bars
// 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