gpt4 book ai didi

javascript - 切换播放/暂停图像按钮 HTML5 视频

转载 作者:搜寻专家 更新时间:2023-10-31 22:39:34 25 4
gpt4 key购买 nike

我有这个代码

var video = document.getElementById('player');
video.volume = 0;
var muteBtn = document.getElementById('mute');
muteBtn.addEventListener('click',function(){
if(video.volume == 1){
video.volume = 0;
muteBtn.src="http://omniawebfactory.com/unik/wp-content/uploads/2016/10/sound-on-beli-1.png";
}
else{
video.volume = 1;
muteBtn.src="http://omniawebfactory.com/unik/wp-content/uploads/2016/10/sound-off-beli-1.png";
}
});


.buttons{
display:block;
width:50px;
height:50px;
background-color:black;
float:left;
}
#control{
width:1000px;
height:50px;
clear:both;
background-color:black;
}

<div id="control">
<img class="buttons"src="http://omniawebfactory.com/unik/wp-content/uploads/2016/10/play-beli-1.png" onClick="document.getElementById('player').play();"/>
<img class="buttons" src="http://omniawebfactory.com/unik/wp-content/uploads/2016/10/pause-beli-1.png" onClick="document.getElementById('player').pause();"/>
<img class="buttons" src="http://omniawebfactory.com/unik/wp-content/uploads/2016/10/sound-on-beli-1.png" id="mute">
</div>

而且我希望播放/暂停按钮像当前的静音按钮一样切换。 https://jsfiddle.net/t6t0maw7/

我尝试复制 javascript 并使用播放/暂停功能对其进行编辑,但没有成功。自由编辑 jsfiddle.net,正确答案将被接受。

最佳答案

JS 代码

var playPause = document.getElementById("play-pause");

playPause.addEventListener("click", function() {
if (video.paused == true) {
// Play the video
video.play();

// Update the button text to 'Pause'
playPause.classList.toggle('pause');
} else {
// Pause the video
video.pause();

// Update the button text to 'Play'
playPause.classList.toggle('pause');
}
});

CSS

button{
height:50px;
width:50px;
border:none;
outline:none;
}

button.play{
background:url("http://omniawebfactory.com/unik/wp-content/uploads/2016/10/play-beli-1.png");
background-size:100%;
}
button.pause{
background:url("http://omniawebfactory.com/unik/wp-content/uploads/2016/10/pause-beli-1.png");
background-size:100%;
}

此处更新fiddle

关于javascript - 切换播放/暂停图像按钮 HTML5 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40219901/

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