javascript - A-frame 改变声音属性 onclick
问题描述
我使用 A 帧 ( https://aframe.io )在我的场景中有一些声音。我的屏幕顶部还有一个按钮按钮。我想知道的是如何做到这一点,以便在单击按钮时,rolloffFactor
声音从 1 减少到 0。当前代码:
<html>
<head>
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script>
function changeRollOff() {
/*Code to change factor of roll off here*/
}
</script>
</head>
<body>
<a-scene>
<button style="position: fixed; z-index: 10000;" onclick="changeRollOff()"
>Change RollOffactor</button>
<a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9"></a-box>
<a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
<a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
<a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>
<a-entity id="river" geometry="primitive: plane" material="color: blue"
position="-10 0 0" sound="src: url(https://cdn.glitch.com/2ecb29ef-7d11-4ac6-b954-e050a39aa59a%2FCHIPTUNE%2C%20BUT%20FUNKY%20Useful.mp3?v=1630627441361); autoplay: true; rolloffFactor: 1;"></a-entity>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
</body>
</html>
解决方案
rolloffFactor
是属性的一个属性sound
。你可以改变它element.setAttribute(component, property, new_value)
:
document.getElementById("river").setAttribute("sound", "rolloffFactor", 0);
推荐阅读
- python-3.x - tkinter.ttk treeview 似乎无法将列名识别为已创建
- php - 无法解析日期 [“2021-05-06 15:24:26 CEST”]:时区指示符 ' ' 无效,但时区存在
- python - 如何使用 Pandas 更新多个 excel 文件并保存更新后的文件而不合并它们
- c# - 返回所有结果的 Odata 深度展开过滤器
- java - 从起点仅提取字符串中的数字
- gradle - 将解决策略与排除相结合
- python - 在字符串中查找单词序列
- android-jetpack-compose - 如何向屏幕添加滑动行为?
- testing - Geb Groovy 测试:如何在不关闭浏览器的情况下关闭当前选项卡?
- python - 从 GUI 小部件更新 QThread