小辉网络社区致力于优质软件,活动线报,游戏辅助,绿色工具等资源共享,好货不私藏!

网站添加随机BGM背景音乐代码

小辉工作室 建站知识

每当网页刷新及打开一次随机播放一首BGM内容十首音乐,网易云、酷狗音乐外链,可以自定义更换,首先,给博客侧边栏加一个空div:<div id="music"></div>
然后就是js了,下面奉上js代码:
<!--音乐内容可自行换-->
<div id="luyumusic"> </div> 
<script>
//还是要分开
var m1 = "http://fs.pc.kugou.com/202009131950/1d645834a0eab1e796f26c9bdd574c18/G231/M06/00/17/Jw4DAF9MabmIQegcAAtJ97FDY1QAAAjigPARswAC0oP166.mp3"; 
//不是因为寂寞才想你
var m2 = "http://fs.pc.kugou.com/202009131952/5ab17e603c6b0849f7cd2d19e4f15a38/G187/M0A/02/11/W4cBAF3zmdGASfhpAHetlns32CY546.mp3"; 
//七秒钟的记忆
var m3 = "http://m7.music.126.net/20200913202022/e9647f3d3fa8cbae102779d146d60849/ymusic/5608/070b/0e52/ab50cc08820a0466700298bc61047eb9.mp3"; 
//黄梅戏DJ
var m4 = "http://m7.music.126.net/20200913202102/69e6651d34be2440ef85ac22df53df0f/ymusic/0652/5208/0553/188e33eab5eb7cf16e95297f62100e15.mp3"; 
//你是人间四月天
var m5 = "http://m8.music.126.net/20200913210602/d62c9137f921c66f491eae891b33529c/ymusic/5152/5552/030c/f860fa842eb8201274264f2d9eda6139.mp3"; 
//爸爸妈妈
var m6 = "http://m8.music.126.net/20200913210655/803e0fc5914faf5209101173289a3552/ymusic/78e7/1070/78e8/08e435a238de98cbdab01c6cd32f2743.mp3"; 
//夏天的风
var m7 = "http://m701.music.126.net/20200913210749/8dd4c571522b8f2e07b7d563a2f230b3/jdymusic/obj/w5zDlMODwrDDiGjCn8Ky/2180586519/98b2/4d51/b6d3/c8c65de6a0bf053a2cd94d1f9473d069.mp3"; 
// 收敛
var m8 = "http://m701.music.126.net/20200913210907/a8b47a8667f4652108b9d2e1fd0fe483/jdymusic/obj/w5zDlMODwrDDiGjCn8Ky/1982156329/01cb/e133/624f/d2778cef75e3bcadaf389b573ad39170.mp3"; 
//所念皆星河
var m9 = "http://m7.music.126.net/20200913203025/c125757b55c8c51cd292aac6d421a844/ymusic/020c/5652/075e/5fcded78c7a8df3f91e404ddbdaf226b.mp3"; 
//你走后1.0
var m10 = "http://m8.music.126.net/20200913211210/464f9206535c7452e200f5a12e82730b/ymusic/015c/0658/000e/664f4e822612bec1739b7d2803cb5f1d.mp3"; 
var x = Math.round(Math.random() * 9); console.log(x); if (x == 0) x = m1 else if (x == 1) x = m2 else if (x == 2) x = m3 else if (x == 3) x = m4 else if (x == 4) x = m5 else if (x == 5) x = m6 else if (x == 6) x = m7 else if (x == 7) x = m8 else if (x == 8) x = m9 else x = m10 var obj = document.getElementById("luyumusic"); obj.innerHTML = "<audio src=" + """ + x + """ + " " + "height="0"" + "autoplay="true"" + "loop="true"" + ">" + "</audio>";</script> 
<!--音乐内容可自行换 -->

温馨提示:如有转载或引用以上内容请将本文链接作为出处标注!百度已收录

免责声明:本站提供的一切软件、教程和内容信息仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序,请支持正版,购买注册,得到更好的正版服务。侵删请致信E-mail:431228450@qq.com

标签 暂无标签
资源分享
评论列表