Okay, I want to control the volume of an HTML5 element using the jQuery Slider element. I have implemented the slide, but can't figure out how to make the value of the slider take the place of the "audio player.volume = ?".
Any help is much appreciated.
The
volume
property is like opacity, it goes between zero and one, one being 100%.Your code is so close, you just need to divide
value
by100
when setting the volume of the<audio>
element:Notice I also put the
change
event handler inside the initialization of theslider
widget.When I paste the above code along into the console while on your webpage, and the volume slider worked as expected.
Also, you can bind to the
slide
event and the volume will change as the user slides theslider
widget, not just after they finish moving the handle:In jQuery you can get the DOM object by simply using
So an example would be:
html
jQuery
Here's a quick jsFiddle example (note: the audio begins on page load).
jQuery:
HTML: