Created
May 28, 2015 16:20
-
-
Save eviltrout/5309a16c554dd008aae4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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