|
|

楼主 |
发表于 2022-2-16 21:05
|
显示全部楼层
全帖代码分享:
- <style>
- #bigPa { position: relative; left:-203px; width: 1000px; height: 569px; background:#333 url('/data/attachment/forum/202202/16/205041jgtngnddt1xnxpvg.jpg') no-repeat center/cover; box-shadow: 0 0 0 2px #111; }
- #gcDiv { width: 300px; float: right; }
- #paDiv { position: relative; top: 10px; 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; }
- #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; }
- #lrcDiv { position: relative; top: 20px; color: #A4D1D7; font-size: 1em; text-shadow: 1px 1px 2px #000; }
- #btn-ro:hover { opacity: 0.8; }
- #btn-ro:active { opacity: 1; }
- @keyframes rol { to { transform:rotate(360deg); } }
- </style>
- <div id="bigPa">
- <div id="gcDiv">
- <!-- 播放器开始 -->
- <div id="paDiv">
- <div id="btn-ro">·</div><!-- 播放按钮 -->
- <div id="jindu"><div id="jd-go"></div></div>
- </div>
- <!-- 播放器结束 -->
- <div id="lrcDiv">歌词同步显示</div>
- </div>
- </div>
- <script language="javascript">
- var lrcAr=[
- ["00:00.00","星辰如眸 (《一见倾心》电视剧片头曲) - 司南"],
- ["00:02.15","词:浅紫"],
- ["00:02.49","曲:浅紫"],
- ["00:02.83","编曲:王德隆"],
- ["00:03.40","和声:司南"],
- ["00:03.85","和声编写:涂忆"],
- ["00:04.55","吉他:陈麒元"],
- ["00:05.15","混音:陈秋洁"],
- ["00:05.73","制作人:江潮"],
- ["00:06.27","监制:浅紫"],
- ["00:06.75","歌曲制作公司:众匠(北京)文化传媒有限公司"],
- ["00:16.41","清晨 烟雨 黄昏 倾世温柔"],
- ["00:23.97","少年 戎装 驰骋 星辰如眸"],
- ["00:31.47","眼神 温暖 坚定 漫笑浮生"],
- ["00:38.18","是一段风华 一指流砂 蓦然回首"],
- ["00:46.33","冬天 雪花飘落的季节"],
- ["00:52.20","你怀中却似春天 花香布满了世间"],
- ["00:59.60","良辰好景入夏天 树荫遮住了眷恋"],
- ["01:07.16","沁心于你在秋天 情深绵绵散落"],
- ["01:14.72","叶翩翩 情渐渐"],
- ["01:24.05","清晨 烟雨 黄昏 倾世温柔"],
- ["01:31.50","少年 戎装 驰骋 星辰如眸"],
- ["01:38.84","眼神 温暖 坚定 漫笑浮生"],
- ["01:45.66","是一段风华 一指流砂 蓦然回首"],
- ["01:54.01","冬天 雪花飘落的季节"],
- ["01:59.66","你怀中却似春天 花香布满了世间"],
- ["02:07.13","良辰好景入夏天 树荫遮住了眷恋"],
- ["02:14.60","沁心于你在秋天 情深绵绵散落"],
- ["02:22.09","叶翩翩 情渐渐"],
- ["02:27.86","冬天 雪花飘落的季节"],
- ["02:33.34","你怀中却似春天 花香布满了世间"],
- ["02:40.87","良辰好景入夏天 树荫遮住了眷恋"],
- ["02:48.37","沁心于你在秋天 情深绵绵散落"],
- ["02:55.89","叶翩翩 情渐渐"],
- ];
- var lrcDiv = document.getElementById('lrcDiv');
- var btn = document.getElementById('btn-ro');
- var jindu = document.getElementById('jindu');
- var aud = document.createElement('audio');
- // 音乐地址放在下行引号内
- aud.src = "http://www.kumeiwp.com/sub/filestores/2022/02/15/cb5d2b49bf5b7fa52e682ce6c6b0c405.mp3";
- aud.loop = true;
- aud.autoplay = true;
- aud.addEventListener('ended', function() { btn.style.animationPlayState="paused"; }, true);
- aud.addEventListener('timeupdate', tmMsg, true);
- 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;
- jindu.innerHTML = "- " + auMs +":" + auSs;
- let jd = (100*aud.currentTime)/aud.duration;
- 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[0].toUpperCase()+direction.substring(1);
- let realNum = obj[offsetDir];
- let positionParent = obj.offsetParent;
- while(positionParent != null){
- realNum += positionParent[offsetDir];
- positionParent = positionParent.offsetParent;
- }
- return realNum;
- }
- btn.onclick = function(){ // 暂停&播放
- aud.paused ? (aud.play(), btn.style.animationPlayState="running") : (aud.pause(), btn.style.animationPlayState="paused");
- }
- //处理lrc歌词数组:时间转换成秒
- for(j=0; j<lrcAr.length; j++){
- lrcAr[j][0] = toSec(lrcAr[j][0]);
- }
- //lrc时间信息转为秒
- function toSec(lrcTime) {
- let tmpAr = lrcTime.split(':');
- lrcTime = tmpAr[0] * 60 + parseInt(tmpAr[1]);
- return lrcTime;
- }
- //同步显示歌词
- aud.ontimeupdate = function() {
- let tt = this.currentTime;
- for(j=0; j<lrcAr.length; j++){
- if(tt > lrcAr[j][0]) lrcDiv.innerHTML = lrcAr[j][1];
- }
- }
- </script>
复制代码
|
评分
-
| 参与人数 2 | 威望 +80 |
金钱 +160 |
经验 +80 |
收起
理由
|
小辣椒
| + 50 |
+ 100 |
+ 50 |
赞一个! |
加林森
| + 30 |
+ 60 |
+ 30 |
赞一个! |
查看全部评分
|