Skip to content

Instantly share code, notes, and snippets.

@eviltrout
Created May 28, 2015 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eviltrout/5309a16c554dd008aae4 to your computer and use it in GitHub Desktop.
Save eviltrout/5309a16c554dd008aae4 to your computer and use it in GitHub Desktop.
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