// 节流
const video = document.querySelector('.video')
// 视频加载完成时,读取并设置播放时间
video.addEventListener('loadeddata',function(){
video.currentTime = localStorage.getItem('currentTime') || 0
})
// 使用节流优化
let timeId
video.addEventListener('timeupdate',function(){
if(timeId !== undefined){
return
}
timeId = setTimeout(()=>{
console.log('timeupdate!')
localStorage.setItem('currentTime',this.currentTime)
// 重置timeId
timeId = undefined
},500)
})
JS详解-手写节流
最新推荐文章于 2025-05-30 22:51:39 发布