I'm doing a website with the skrollr plugin and I'm almost done with the pictures and scrolling itself, so I'm trying to add the audio now, but I can't seem to make the audio start and stop when I want it to. This is the script I am currently working with:
<script>
$(window).scroll(function() {
var height = $(document).height() - $(window).height();
var scroll = $(window).scrollTop();
var audioElm = $('#soundTour').get(0);
audioElm.play();
audioElm.volume = 1 - $(window).scrollTop()/height;
console.log(audioElm.volume);
});
</script>
This makes my audio start as soon as the website is loaded and fade out across the span of the entire website, so when you've scrolled to the bottom, it's completely silent. I've tried messing with the "height" variable in the script, but to no avail. The sound always ends up heavily lowered, but still faintly playing in the background. Is there a way to make it shut up at a certain scroll point? For example, make the audio play at $(window).scrollTop() = 500 and stop at $(window).scrollTop() = 3000?