js文件
var objFun = {
bindEvent(boxID){
this.wrapperDom = document.getElementById(boxID);
this.audio = this.wrapperDom.querySelector('audio');
this.moon = this.wrapperDom.querySelector('.moon');
this.sun = this.wrapperDom.querySelector('.sun');
this.perinfo = this.wrapperDom.querySelector('.per');
var flag = false;
var dis;
//鼠标拖拽事件
this.moon.onmousedown = function (e) {
flag = true;
// 计算出鼠标落下点与月亮边界的距离
dis = e.clientX - this.moon.offsetLeft;
}.bind(this);
this.wrapperDom.onmousemove = function (e) {
if (!flag) {
return;
};
// 根据拖拽距离设置当前拖拽元素的位置
this.moon.style.left = (e.clientX - dis) + 'px';
// 调用控制音量的函数
this.getVoice()