python判断数字在哪个区间_js 如何判断一个数字在一个数字数组的那个区间?

卧槽,我曾经搞了个极简的音乐播放器

不过,是直接获取标准格式的lrc文件,然后前端分割。

然后我的方法不是数组遍历,因为前端js里面一切皆对象,对象的查找快多了。

代码

https://github.com/anchengjia...

思路:

把分割音频后按照起始点向下取整存一个对象,然后currentTime每次向下取整,然后比较两个数字进行比较,如果一样,不管,不然就++,用++后的值匹配成一个选择器,直接去dom里面找是都存在,然后继续。

updateLyric(ev) {

let audio = ev.target;

// currentTime

var currentTime = ~~audio.currentTime;

if (!this.source.lrc[currentTime] || this.currentTime === currentTime) return;

this.currentTime = currentTime;

this.currentLine++;

if (this.currentEle) this.currentEle.classList.remove('on');

this.currentEle = this.lrcList.querySelector(`li:nth-child(${this.currentLine})`);

this.currentEle.classList.add('on');

if (this.currentLine > 5 && this.currentLine + 5 <= this.source.len) this.lrcList.scrollTop = (this.currentLine - 5) * this.lineHeight;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值