gpt4 book ai didi

javascript - Js 音频音量 slider

转载 作者:行者123 更新时间:2023-12-02 23:01:49 26 4
gpt4 key购买 nike

我是新手,我有一个问题。我怎样才能放一个音量 slider ?谢谢!!
我暂时找不到任何适合我的代码,希望您能帮助

HTML: <a id="play-pause-button" class="fa fa-play">
JavaScript:

<script type="text/javascript">
var audio = new Audio("http://21273.live.streamtheworld.com/LOS40_DANCE.mp3");
$('#play-pause-button').on("click",function(){
if($(this).hasClass('fa-play'))
{
$(this).removeClass('fa-play');
$(this).addClass('fa-pause');
autoplay = true;
audio.play();
audio.muted = false;
}
else
{
audio.muted = true;
$(this).removeClass('fa-pause');
$(this).addClass('fa-play');
}
});

audio.onended = function() {
$("#play-pause-button").removeClass('fa-pause');
$("#play-pause-button").addClass('fa-play');
};

</script>

最佳答案

我已经对此进行了测试,并且可以正常工作。
HTML

<input type="range" id="volume-control">
JS
let audio = new Audio("http://21273.live.streamtheworld.com/LOS40_DANCE.mp3");

let volume = document.querySelector("#volume-control");
volume.addEventListener("change", function(e) {
audio.volume = e.currentTarget.value / 100;
})
我希望它有帮助

关于javascript - Js 音频音量 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62160275/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com