[英]How to change icon on click?
I have a button on my page that looks like this: https://pierdzialka.misumi.me/d2TVS.png Once you click it the playPreview()
is called to play an audio file.我的页面上有一个按钮,如下所示: https://pierdzialka.misumi.me/d2TVS.png单击它后,将
playPreview()
来播放音频文件。
var preview = document.getElementById("BeatmapPreview");
var isPlaying = false;
function playPreview() {
if (isPlaying) {
preview.pause();
classList.toggle("play");
} else {
preview.play();
classList.toggle("pause");
}
};
preview.onplaying = function() {
isPlaying = true;
};
preview.onpause = function() {
isPlaying = false;
};
I'm trying to make it change the icon class from play to pause on click too, the code for that is here:我试图让它改变图标 class 从播放也暂停点击,代码在这里:
<a onclick="playPreview()" class="ui blue labeled icon button">
<i class="play icon"></i>
{{ $.T "Play" }}
</a>
How can I achieve this?我怎样才能做到这一点?
Final thing too is for the audio actually being played, that is placed further up and is just this:最后一件事也是实际播放的音频,它被放置得更远,就是这样:
<audio id="BeatmapPreview">
<source src="https://misumi.me/preview/{{ .Beatmapset.ID }}.mp3">
</audio>
Try this document.getElementById('yourIconElementId').classList.toggle("play");
试试这个
document.getElementById('yourIconElementId').classList.toggle("play");
Add your Icon Element selector before classList
在
classList
之前添加您的图标元素选择器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.