绿叶清舟 发表于 2022-2-24 17:36

我的最爱

本帖最后由 绿叶清舟 于 2022-2-26 17:16 编辑 <br /><br /><style type="text/css">
#waiDiv { margin:10px; padding:8px; width:400px; background:#696969; border-radius:10px; box-shadow:2px 2px 4px #000; display:flex; flex-direction:column; position:relative; }
#audDiv { width:100%; display:flex; flex-direction:row; align-items:center; font-size:10px; position: relative; }
#add1 { margin-left: 12px; background:#eee; text-align:center; width:20px; height:20px; line-height:20px; border-radius:50%; cursor:pointer; }
#add1:hover { color: red; }
#mLiDiv { margin-top: 10px; background:#eee; color:#000; min-height:100px; padding:10px; border:1px solid olive; font-size:14px; column-count: 2;}
#mLiDiv a { text-decoration: none; cursor:pointer; }
#mLiDiv a:hover { color:red; }
#prompt { position:absolute; left:200px; top:50px; width:400px; padding:6px 12px; background:silver; font-size:12px; display:none; box-shadow:1px 1px 1px #666; border-radius:2px; }
#prompt input { outline:none; }
#prompt input { margin:4px;padding:4px; width:392px; }
#prompt input { border-radius:4px; cursor:pointer;border:1px solid gray; border-radius:3px; box-shadow: 1px 1px 2px #444; }
#audDiv input, #audDiv input { cursor:pointer; }
#paDiv { margin: auto; width: 220px; display: flex; align-items: center; border: 1px solid olive; border-radius: 8px 0px 8px 0px; background: rgba(0,0,0,.8); box-shadow: 1px 1px 2px #000; position: relative; }
#jindu { position: relative; width: 200px; height: 8px; line-height: 8px; font-size: 10px; color: #eee; text-align: center; background: linear-gradient(90deg, olive, green) no-repeat; background-size: 8px 0px; cursor: pointer; }
#btn-ro { width: 20px; height: 20px; line-height: 20px; font-size: 12px; background: linear-gradient(blue, silver, red); outline:none; color: white; border-radius: 50%; text-align: center; cursor: pointer; animation: rol linear 2s infinite; }
#btn-ro:hover { opacity: 0.8; }
#btn-ro:active { opacity: 1; }
@keyframes rol { to { transform:rotate(360deg); } }
</style>

<DIV align=center color=#ff0000 >
<tablestyle="position: relative;LEFT: -320px; width:1200px;TOP: 180px"border="0" cellspacing="0" cellpadding="0">
<TBODY><TR><TD height=800 background=https://pic.imgdb.cn/item/62174f692ab3f51d91340c5f.jpg>
</TD></TR>
</table></div><BR><BR><BR><BR><BR><BR><BR>

<DIVstyle="position: relative; opacity: 0.5; LEFT: -100px; TOP: -280px">
<div id="waiDiv">
      <div id="audDiv">
                <div id="paDiv">
                        <div id="btn-ro">·</div>
                        <div id="jindu"><div id="jd-go"></div></div>
                </div>
                <input id="muted" type="checkbox" onclick="aud.muted = this.checked ? true : false">静音
                <input id="dqxh" type="radio" name="rad" checked="checked" onclick="howplay()" />单曲
                <input id="lhbf" type="radio" name="rad" onclick="howplay()" />轮播
                <div id="add1">+</div>
      </div>
      <div id="mLiDiv"></div>
      <div id="prompt">
      <div>添歌</div>
                <input type="text" id="mName" placeholder="歌曲名称" /><br />
                <input type="text" id="mUrl" placeholder="歌曲地址" /><br />
                <div style="text-align:center;">
                        <input id="subMe" type="button" value=" 添加 " />
                        <input id="cancelMe" type="button" value=" 算了 " />
                </div>
      </div>
</div>
</div>

<script>
//音乐数据 注意最后一个结尾不要逗号但前面每一个的结尾都要有逗号
var muAr = [
      ["http://music.163.com/song/media/outer/url?id=526472472.mp3","乱红","陈悦"],
      ["http://music.163.com/song/media/outer/url?id=5253675.mp3","升"],
      ["https://www.kumeiwp.com/sub/filestores/2022/02/23/3b348f94dbd4c2c843e7976a776bd154.mp3","呼吸"],
      ["https://joy127.jstools.net/uploads/mp3/202202/23/20226216270d12739135688.mp3","离弦"],
      ["http://music.163.com/song/media/outer/url?id=25730799.mp3","最后一只舞"],
      ["https://www.kumeiwp.com/sub/filestores/2022/02/23/f59f9c9c188a99ab7c82cf9fdbf66e34.mp3","西出长安"],
      ["https://www.kumeiwp.com/sub/filestores/2022/02/23/06952ab784aff1d6cee8b180ee3c6aeb.mp3","谜"],
      ["http://music.163.com/song/media/outer/url?id=1437070924.mp3","这支烟灭了以后"],
      ["http://music.163.com/song/media/outer/url?id=28725740.mp3","Asoka Theme"],
      ["http://music.163.com/song/media/outer/url?id=5264840.mp3","Going home - Kenny G"],
];

var btn = document.getElementById('btn-ro');
var jindu = document.getElementById('jindu');
var aud = document.getElementById('myPlayer');
var mLi = document.getElementById('mLiDiv');
var mAdd = document.getElementById('add1');
var prom = document.getElementById('prompt');
var cancelMe = document.getElementById('cancelMe');
var subMe = document.getElementById('subMe');
var dqxh = document.getElementById('dqxh');
var lhbf = document.getElementById('lhbf');
var aud = document.createElement('audio');
aud.loop = true;
var playIdx = 0; //当前播放索引
if(aud.paused) btn.style.animationPlayState="paused";
//写歌单
var str = "";
for(j=0; j<muAr.length; j++) {
      str += (j+1) + ".<a id='list" + j + "' onclick='iPlay(" + j + ")' >" + muAr + "</a><br />";
}
mLi.innerHTML += str;

function iPlay(idx){ //播放函数
      playIdx = idx;
      aud.src = muAr;
      aud.play();
      aud.addEventListener('timeupdate', tmMsg, true);
      aud.addEventListener('ended', function() { btn.style.animationPlayState="paused"; }, true);
      btn.style.animationPlayState="running";
      nameRed(playIdx);
}

function howplay(){ //单曲&轮播处理
      dqxh.checked ? aud.loop = true : (aud.loop = false,playNext(),aud.addEventListener('ended',playNext,false));
      prom.style.display = "none";
}

function playNext(){ //处理下一首
      if(aud.paused) iPlay(playIdx);
      playIdx += 1;
      if(playIdx >= muAr.length) playIdx = 0;
}

function nameRed(){ //歌单着色
      for(k=0;k<muAr.length;k++){
                let listId = "list" + k;
                document.getElementById(listId).style.removeProperty("color");
      }
      listId = "list" + playIdx;
      document.getElementById(listId).style.color = "red";
}

function tmMsg(){ //进度条
      let auT = Math.floor(aud.duration - aud.currentTime);
      let auM = auT / 60;
      let auMs = parseInt(auM);
      if (auMs <10) auMs = "0" + auMs;
      let auS = auT % 60;
      let auSs = Math.round(auS);
      if (auSs < 10) auSs = "0" + auSs;
      let jd = (100*aud.currentTime)/aud.duration;
      if(jd>0) {
                jindu.innerHTML = "- " + auMs +":" + auSs;
                jindu.style.backgroundSize = jd+ "% 8px";
      }
}

jindu.onclick = function(){ //进度控制
      let w = offset(jindu,"left");
      let x = (event.clientX - w) * aud.duration / jindu.clientWidth;
      aud.currentTime = x;
}

function offset(obj,direction){//获取元素总偏移量
      let offsetDir = "offset" + direction.toUpperCase()+direction.substring(1);
      let realNum = obj;
      let positionParent = obj.offsetParent;
      while(positionParent != null){
                realNum += positionParent;
                positionParent = positionParent.offsetParent;
      }
      return realNum;
}

btn.onclick = function(){ //光盘按钮点击事件
      aud.paused ? (aud.play(), btn.style.animationPlayState="running") : (aud.pause(), btn.style.animationPlayState="paused");
}

mAdd.onclick = function(){ prom.style.display = "block"; } //呼出加歌界面
cancelMe.onclick = function(){ prom.style.display = "none"; } //放弃加歌

subMe.onclick = function(){ //加歌并播放新歌
      let uri = document.getElementById('mUrl');
      let name = document.getElementById('mName');
      let tnum = muAr.length;
      let str1 = uri.value.trim();
      let str2 = name.value.trim();
      if(str1 !="" && str2 != ""){
                muAr = ;
                mLi.innerHTML += (tnum+1) + ".<a id='list" + tnum + "' onclick='iPlay(" + tnum + ")' >" + str2 + "</a><br />";
                iPlay(tnum);
                uri.value = "";
                name.value = "";
      }
      prom.style.display = "none";
}
//自动播放(默认播放第一首)
iPlay(playIdx);
</script>

东篱闲人 发表于 2022-2-24 18:27

师傅高雅!{:5_116:}

冬天的雨 发表于 2022-2-24 18:45

这四个字特别漂亮{:4_199:}

冬天的雨 发表于 2022-2-24 18:46

美丽也是特别漂亮{:4_199:}

冬天的雨 发表于 2022-2-24 18:48

有停止按钮 没有停止音乐{:4_203:}

红影 发表于 2022-2-24 18:50

好美的制作,这些音乐也是影子的最爱{:4_187:}

绿叶清舟 发表于 2022-2-24 20:42

红影 发表于 2022-2-24 18:50
好美的制作,这些音乐也是影子的最爱

{:4_179:}抱抱影 ,俺爱的你一定爱了{:4_173:}

绿叶清舟 发表于 2022-2-24 20:43

冬天的雨 发表于 2022-2-24 18:48
有停止按钮 没有停止音乐

按静音就没声音了,边上那个加号不是停止按钮啊

绿叶清舟 发表于 2022-2-24 20:44

冬天的雨 发表于 2022-2-24 18:46
美丽也是特别漂亮

谢谢冬雨,难得看到你这个时候来的了

绿叶清舟 发表于 2022-2-24 20:44

东篱闲人 发表于 2022-2-24 18:27
师傅高雅!

谢谢东篱,哪有啊

樵歌 发表于 2022-2-24 20:45

好美好美,你抢了我的最爱!{:4_334:}

东篱闲人 发表于 2022-2-24 20:47

绿叶清舟 发表于 2022-2-24 20:44
谢谢东篱,哪有啊

谁说不是,俺揍他。。。。{:5_165:}

绿叶清舟 发表于 2022-2-24 20:57

东篱闲人 发表于 2022-2-24 20:47
谁说不是,俺揍他。。。。

这么厉害,不敢说了{:4_189:}

绿叶清舟 发表于 2022-2-24 20:57

樵歌 发表于 2022-2-24 20:45
好美好美,你抢了我的最爱!

谢谢樵歌,可以一起爱啊{:4_189:}

红影 发表于 2022-2-24 21:20

绿叶清舟 发表于 2022-2-24 20:42
抱抱影 ,俺爱的你一定爱了

是啊,我们如此相似,喜欢的也肯定相近呢{:4_187:}

小辣椒 发表于 2022-2-24 21:41

清舟这个做的漂亮,播放器移动了位子。小辣椒可以学习了{:4_171:}

绿叶清舟 发表于 2022-2-24 21:52

小辣椒 发表于 2022-2-24 21:41
清舟这个做的漂亮,播放器移动了位子。小辣椒可以学习了

辣椒好,还加了一点点透明的,不喜欢可以去掉了

小辣椒 发表于 2022-2-24 21:55

谢谢清舟,其实现在我玩一次,以后再玩,但这个移动播放器位子我得学习一下。想玩的东西多,时间不够的{:4_173:}

绿叶清舟 发表于 2022-2-24 22:00

小辣椒 发表于 2022-2-24 21:55
谢谢清舟,其实现在我玩一次,以后再玩,但这个移动播放器位子我得学习一下。想玩的东西多,时间不够的{:4_ ...

不客气了,一下来这么多都来不及玩了

大猫咪 发表于 2022-2-24 22:20

最喜欢乱红了, 箫声如水,在钢琴的映衬下起起落落,清淡悠远却意境无穷。。

清舟好分享,真棒!

{:4_204:}{:4_199:}
页: [1] 2
查看完整版本: 我的最爱