Audio对象
2016-07-28 17:47
260 查看
var soundButtons = document.querySelectorAll('.button-sound'); for (var i = 0; i < soundButtons.length; i++) { var soundButton = soundButtons[i]; var soundName = soundButton.attributes['data-sound'].value; prepareButton(soundButton, soundName); } function prepareButton(buttonEl, soundName) { console.log(__dirname); buttonEl.querySelector('span').style.backgroundImage = 'url("img/icons/' + soundName + '.png")'; var audio = new Audio(__dirname + '/wav/' + soundName + '.wav'); buttonEl.addEventListener('click', function () { audio.currentTime = 0;//把时间位置设置为从 0 秒播放 audio.play(); }); }
HTMLAudioElement接口
注:
__dirname + '/wav/' + soundName + '.wav'中存放着的是
.wav格式的音乐。
相关文章推荐
- android获取内存信息方法
- HDU 1181变形课(DFS)
- ABAP 选择界面搜索帮助
- LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers
- HDU5763 Another Meaning(KMP+dp)
- <poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies
- Android 快速开发系列 ORMLite 框架最佳实践 标签: AndroidORMLite 2014-09-07 23:47 62916人阅读 评论(36) 收藏 举报 分类: 【Androi
- 交换数
- PhthonDjango Server Develop For Mac
- iOS GCD完全解析
- service
- 获取tableviewCell在当前屏幕中的坐标值
- eCryptfs - mount系统调用
- gdb的时候行号错乱
- tp使用阿里大于的短信接口
- NYOJ(680),摘枇杷,(暴力,或者二分搜索)
- spring笔记1
- 10、Java并发编程:并发容器之ConcurrentHashMap
- 前端干货整合(二)
- android中 IntDef注解的使用