• 给你的网页添加一个随机的BGM


    大晚上的,突然想到,我这么喜欢听歌的人,博客里怎么能少了BGM呢,说干就干。

    首先,给博客侧边栏加一个空div:<div id="music"></div>

    然后就是js了,下面奉上js代码:

    //500英里
    var m1="http://win.web.rh03.sycdn.kuwo.cn/a350d16bcc9f510464e06e582c7a3a3e/5ab141af/resource/a1/20/25/1132448623.aac";
    //我爱你
    var m2="http://dl.stream.qqmusic.qq.com/C400001icZKT0tqWH5.m4a?vkey=6B4D43439347D32461B05BBD450DFD301A40F3AF3A71EED192BF286D033478A106CF6A757189F5DFA5F02FDFBF7EBF9B653C8F9DF8371358&guid=9228674034&uin=0&fromtag=66";
    //my all(live)
    var m3="http://m128.xiami.net/812/634530812/2102860445/1796788604_1505891215426.mp3?auth_key=1522119600-0-0-18fb001c1d285828e630347a4b5f0e16";
    //let her go
    var m4="http://dl.stream.qqmusic.qq.com/C400000Gb5s20okAGc.m4a?vkey=F310BDE485F643A1CDA95FAC57B4DF3750F62F08C9F3B4B4DBD1DBCBB0E0D85FF44CF083982EE30FD977AB527E918F3089C5CD58E1E3CA86&guid=9228674034&uin=0&fromtag=66";
    //see you again
    var m5="http://dl.stream.qqmusic.qq.com/C4000022R1L82mb8Hp.m4a?vkey=286FB65F8EE1C86310E39B4C343289DA2CBB1610886A1C161701915CCFCC759AB59265968DD993C34E269E96F21E600782EFC75FE4C2BC6E&guid=9228674034&uin=0&fromtag=66";
    //try
    var m6="http://dl.stream.qqmusic.qq.com/C400001jrqse2O46fv.m4a?vkey=691D221BB8E39B024D43E22FDB44BDD61B707522EF109E4806BFEA19D1DAF8C8FC2E5EB8B706A3A95BF7944307930F96585F25A269A4927D&guid=9228674034&uin=0&fromtag=66";
    //stay here forever
    var m7="http://dl.stream.qqmusic.qq.com/C400001Af4F71o2eWL.m4a?vkey=B85249D922AF51639FCBEB407E0C0BC862C5332EDD86553CF01F308DD23446B96348E904972D852D9AD456FEF5C0D5BFD5CB5209DC054C31&guid=9228674034&uin=0&fromtag=66";
    //任意门
    var m8="http://dl.stream.qqmusic.qq.com/C400001vpWmD4Bjl3l.m4a?vkey=0D778A482A2AB41F9CD681FF53ABBA3F3A727B7730582722D75DA0C304118F6E6F453C2A56A5BAE1F7A38FA0E9D1AADBEB01520358A0567A&guid=9228674034&uin=0&fromtag=66";
    //晴天
    var m9="http://dl.stream.qqmusic.qq.com/C4000039MnYb0qxYhV.m4a?vkey=91642C03D40616ACB115987FC15FAA3B8BB8B04E9C80130B9FD9EF2F8EFA6535D74BEDFCE813283A4929010D6810C95BDE86C8E5CF20DCD4&guid=9228674034&uin=0&fromtag=66";
    //七里香
    var m10="http://dl.stream.qqmusic.qq.com/C400004Z8Ihr0JIu5s.m4a?vkey=1E323D98E2CB5EAD98C937FE45EB6147D2F2CF96407F37853ABA0D14C75E35D3E94B9B0793E08A4EB86C7F8620110793EFDD49DA0DC913B2&guid=9228674034&uin=0&fromtag=66";
    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("music");
    obj.innerHTML='<audio src='+'"'+x+'"'+' '+'height="0"'+'autoplay="true"'+'loop="true"'+'>'+'</audio>';

    如此,就实现了每次刷新页面的时候,随机播放上面10首歌里面的任意一首。

    So easy!

  • 相关阅读:
    [置顶] Ubuntu 12.04以上如何恢复GNOME传统界面
    Cstyle的UEFI导读之SEC第一篇 Reset Vector
    二叉排序树的实现
    【最长上升子序列】HDU 1087——Super Jumping! Jumping! Jumping!
    java中的代理
    eclipse连接远程hadoop集群开发时0700问题解决方案
    eclipse连接远程hadoop集群开发时权限不足问题解决方案
    垂死或涅槃重生 -- Delphi XE5 我们将宣布感情的回归
    百度地图 Android SDK
    MySQL第五个学习笔记 该数据表的操作
  • 原文地址:https://www.cnblogs.com/eco-just/p/8614930.html
Copyright © 2020-2023  润新知