I have an autofade button attached to each instance of my audio tracks:
<input type="button" id="autofadebtn<?php echo $track;?>" value="Fade Out"
onclick="$(document).ready(function()
{
$('#<?php echo $track;?>')[0].volume = .5;
$('#<?php echo $track;?>').animate({volume: 0}, 30000);
});
$('#<?php echo $track;?>').promise().done(function() {
$('#<?php echo $track;?>').trigger('pause');
});
"
>
I also have a volume slider:
var audio<?php echo $track;?> = document.getElementById("<?php echo $track;?>");
var slider<?php echo $track;?> = document.getElementById("slider<?php echo $track;?>");
var display<?php echo $track;?> = document.getElementById("display<?php echo $track;?>");
slider<?php echo $track;?>.addEventListener("input", sliderActions);
function sliderActions( )
{
var newVolume = slider<?php echo $track;?>.value;
display<?php echo $track;?>.innerText = newVolume; // range 0 to 100
audio<?php echo $track;?>.volume = newVolume / 100; // range 0 to 1
}
My issue is that I would like my autofade button to start at the volume the user moves the volume slider to. Currently the auto fade starts at .5. I can't work out which variable to use from the volume slider. The autofade button is within the input tag whilst the volume slider script is at the bottom of the page.
I've tried replacing the volume = .5 in the autofade with the named variables from the volume slider but each time the autofade stops working.
onclick="$(document).ready(function() ...- that is one of the worst constructs I have ever seen, when it comes to event handling. Surprised it does anything at all, considering it appears to try and set areadyhandler for the document, when the element gets clicked (by which time ready will probably already have passed.)sliderActions? I'm assumingaudio<?php echo $track;?>in there, and$('#<?php echo $track;?>')in your click handler, are effectively the same element? So why do you need to set it again in your click handler, can't just just "animate" from the current volume?<?php echo $track;?>in varname and and getElementById looks like you have several of these on the page. If you delegate you do not need this code at all.