Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created June 19, 2015 17:17
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 rocktronica/5960e5e18e9b74497c25 to your computer and use it in GitHub Desktop.
Save rocktronica/5960e5e18e9b74497c25 to your computer and use it in GitHub Desktop.
folley.js
(function(doc, undefined) {
var soundEffectStable = [
new Audio("/media/sounds/comical.wav"),
new Audio("/media/sounds/dirp.wav"),
new Audio("/media/sounds/whip-and-bonk.wav"),
];
for (var i = 0; i < 4; i++) {
soundEffectStable = soundEffectStable.concat(soundEffectStable);
}
var boom = function() {
var randomAvailableSoundEffects = soundEffectStable.filter(function(soundEffect) {
return soundEffect.paused;
});
var randomAvailableSoundEffect = randomAvailableSoundEffects[
Math.floor(randomAvailableSoundEffects.length * Math.random())
];
if (randomAvailableSoundEffect) {
randomAvailableSoundEffect.play();
};
};
var events = ["click", "keypress", "change"];
events.forEach(function(event) {
doc.addEventListener(event, boom, true);
});
var isScrolling = false;
var droppingSoundEffect = new Audio("/media/sounds/dropping.wav");
var boomSoundEffect = new Audio("/media/sounds/boom.wav");
var endDroppingEffect;
doc.addEventListener("scroll", function() {
isScrolling = true;
droppingSoundEffect.play();
clearTimeout(endDroppingEffect);
endDroppingEffect = setTimeout(function() {
isScrolling = false;
droppingSoundEffect.pause();
droppingSoundEffect.currentTime = 0;
boomSoundEffect.play();
}, 500);
});
var teethBrushingSoundEffect = new Audio("/media/sounds/teeth-brushing.wav");
var endTeethBrushingEffect;
doc.addEventListener("mousemove", function() {
if (isScrolling) { return; }
teethBrushingSoundEffect.play();
clearTimeout(endTeethBrushingEffect);
endTeethBrushingEffect = setTimeout(function() {
teethBrushingSoundEffect.pause();
}, 100);
});
}(document));
@rocktronica
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment