如果你看到本段文字,说明该页面未正常加载全局JS,部分功能将无法使用,请点击 刷新 重新加载页面。
如果打开页面显示缩略图创建出错,请点击刷新或页面右上WIKI功能中的刷新按钮清除页面缓存并刷新,如果还有问题,请多尝试几次。
全站通知:

用户讨论:丩卩夂忄/代码存档/sound.js

来自碧蓝航线WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索
/*
HTML内容:<div class="sound">音乐文件地址</div>
CSS内容:.sound{font-size:0px}
*/


sound=document.getElementsByClassName("sound")
for(i=0;i<sound.length;i++){
	soundLink=sound[i].innerHTML
	sound[i].innerHTML='<p><div class="audio_player audio_player-stopped" onclick="soundPlay(this)"><audio class="audio_player" src="'+soundLink+'" onended="soundStop(this)" preload="none" controls="" style="width: 0px; height: 0px; visibility: hidden;"></audio><div class="audio_player-playpause"></div></div></p>'
}
allPlayer=document.getElementsByClassName("audio_player")
function soundPlay(div){
	for(i=0;i<allPlayer.length;i++){
		if(allPlayer[i].classList.contains("audio_player-playing")&&allPlayer[i]!=div){
			allPlayer[i].classList.remove("audio_player-playing")
			allPlayer[i].classList.add("audio_player-stopped")
			allPlayer[i].childNodes[0].load()
		}
	}
	if(div.classList.contains("audio_player-stopped")){
		div.classList.remove("audio_player-stopped")
		div.classList.add("audio_player-playing")
		div.childNodes[0].play()
	}
	else{
		div.classList.remove("audio_player-playing")
		div.classList.add("audio_player-stopped")
		div.childNodes[0].load()
	}
}
function soundStop(audio){
	audio.parentNode.classList.remove("audio_player-playing")
	audio.parentNode.classList.add("audio_player-stopped")
}