2

I have html5 webpage, with a slider and an audio track. I do not reffer to the sound tag property controls = "controls" (). I want my slider to control the volume from the audio file. If I use in my body tags , the following code it`s working perfectly. If I use in my body tags , the result is a deafening noise . This is my code:

HTML

<!doctype html>
<html lang="en">

<head>

<title>Rain</title>
<meta charset="utf-8">

<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.23.custom.css">
<link rel="stylesheet" type="text/css" href="css/style.css">

</head>

<body onLoad="run();">

<div id="slider"></div>


<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/ui.js"></script>
</body>
</html>

JS

// Invoke new Audio object
var ad = new Audio('rainloop.mp3');

//default play audio
ad.play();

//volume slider
$('#slider').slider({
min:0,
max:100,
step:1,
value:50,
slide: function(){

    ad.volume = parseFloat(this.value / 10);
}

} );

I think the problem its here : ad.volume = parseFloat(this.value / 10); Ive tried also : ad.volume = parseFloat(this.value) and ad.volume = parseFloat(this.value / 100) and it`s still making a incomprehensible noise.

4

1 回答 1

1

尝试在 0 和 1 之间操作音量值,其中 0 是静音 (0%),1 是最大音量 (100%) http://www.w3schools.com/html5/av_prop_volume.asp

检查控制台日志您在这部分代码中得到的内容:

parseFloat(this.value / 100) 
于 2012-09-23T22:20:23.493 回答