jquery - 如何在 pixi 中创建播放和暂停按钮
问题描述
我创建了一个网页。其中有背景音乐。
我想在音乐中添加(播放和暂停)按钮。我是 pixi 的新手,所以我不知道该怎么做。
我的代码:
<script>
PIXI.sound.Sound.from({
url: 'musical-11.mp3',
loop:true,
preload: true,
loaded: function(err, sound) {
sound.play();
}
});
</script>
解决方案
我的代码:
<button class="btn btn-lg btn-primary off" id="paused">
<span class="glyphicon glyphicon-pause off"></span>
<span class="glyphicon glyphicon-play on"></span>
</button>
<script>
PIXI.sound.Sound.from({
url: 'vsg-music2.mp3',
loop:true,
preload: true,
loaded: function(err, sound) {
sound.play();
document.querySelector("#paused").addEventListener('click', function() {
const paused = PIXI.sound.togglePauseAll();
this.className = this.className.replace(/\b(on|off)/g, '');
this.className += paused ? 'on' : 'off';
});
}
});
</script>
CSS:
.btn
{
outline: none !important;
}
.btn .off,
.btn .on {
display: none;
}
.btn.off .off`enter code here`,
.btn.on .on {
display: inline-block;
}
推荐阅读
- gis - 使用地理服务器在 postgis 视图上的 WFS-T
- facebook - 无法在 facebook 即时文章中点击提交 url
- php - 试图获取非对象的属性,错误集中在“.$users->username”上。
- jquery - jquery:如何在 prevUntil 中查找
- asp.net-core - ASPNET 核心路由
- javascript - 整页缩放功能
- c# - XRay 和 XUnit 报告器错误地解析多个测试用例属性
- django - FormView 不在 Django 中保存数据
- python - PyTorch 安装问题 - 使用 Jupyter notebook 和 Conda navigator 找不到包
- r - 在 Jupyter Lab 中从 Rmarkdown .Rmd 文件运行 R 代码时如何调整绘图大小?