I have been looking for a long time for a code to fade the volume by scrolling the site window up and down, but I found only a beautiful code with the function 1 -> 0. (Fade HTML5 audio (adjust volume) using jQuery (window).scroll)
I tried to juggle the values of the function, but it didn't work out...
Please, could you advise how to set the sound distribution on the page not 1 -> 0, but 0 -> 1 -> 0 with restrictions on the top and bottom of the site page in pixels or percentages?
p.s.enter image description here I would like to formulate this code as a spice in my ready-made website in the readymag constructor. I don't know how to write websites from scratch right now.
<article>
<audio loop id="soundTour" src="http://brendansheehanworks.com/100/aaaa/examples/b/longdong.wav"></audio>
</article>
<script>
$(document).ready(function() {
var audioElm = $('#soundTour').get(0);
audioElm.play();
var height = $(document).height() - $(window).height();
$(window).scroll(function() {
audioElm.volume = 1 - $(window).scrollTop() / height;
console.log(audioElm.volume);
});
});
</script>