Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require("./reset.scss");
require("./crotchzombie.scss");
$(window).ready(function() {
const $logo = $('#logo');
let played = false;
function playAudio() {
if (played) { return; }
played = true;
const audio = new Audio('/mp3/crotch.mp3');
audio.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
audio.play();
}
function randomTime() {
return Math.floor(Math.random() * 3000) + 1000;
}
function fadeIn() {
const opacity = (Math.random() * 0.4) + 0.6;
$logo.animate({ opacity }, randomTime(), fadeOut);
}
function fadeOut() {
const opacity = (Math.random() * 0.3) + 0.1;
$logo.animate({ opacity }, randomTime(), fadeIn);
}
// iOS can't autoplay, have to click
const ua = window.navigator.userAgent;
const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
if (iOS) {
$('#logo').on('click', playAudio);
} else {
playAudio();
}
fadeOut();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.