页面跳转时背景音频不间断
作者:
Mracale | 来源:发表于
2020-08-24 17:36 被阅读0次var soundBgm=document.getElementById("music");
//判断本地是否有存储过音频播放时间
if(sessionStorage.bgmTime==null){
//若没有时,从头自动播放
soundBgm.currentTime=0;
}else{
//若有存储的则,取出本地存储的音频播放的暂停时间
var curTime=window.sessionStorage.getItem("bgmTime");
sessionStorage.bgmPlay=soundBgm.bgmPlay;
//从暂停时间开始接着播放
soundBgm.currentTime+=curTime;
}
//页面跳转时将本页面音频最后截至时间存储下来
function fun(){
soundBgm.pause();
sessionStorage.bgmPlay=soundBgm.bgmPlay;
sessionStorage.bgmTime=soundBgm.bgmPlay?soundBgm.currentTime+soundBgm.context.currentTime-soundBgm.startTime:soundBgm.currentTime;
location.href='跳转的url';
}
本文标题:页面跳转时背景音频不间断
本文链接:https://www.haomeiwen.com/subject/epnnjktx.html
网友评论