話不多說,直接看效果圖:

代碼如下:
-
-
<html lang="en">
-
<head>
-
<meta charset="UTF-8">
-
<meta name="Generator" content="EditPlus®">
-
<meta name="Author" content="">
-
<meta name="Keywords" content="">
-
<meta name="Description" content="">
-
<title>音樂播放器</title>
-
<style type="text/css">
-
*{
-
margin:0px;
-
padding:0px;}
-
#phone{
-
width:320px;
-
height:600px;
-
background:#000;
-
margin:100px auto;}
-
.top
-
{
-
width:320px;
-
height:23px;
-
background:url("images/1.png")
-
}
-
.tittle
-
{
-
width:320px;
-
height:30px;
-
background:url("images/2.png");
-
color:#fff;
-
text-align:center;
-
line-height:30px;
-
font-size:18px;
-
}
-
.singer
-
{
-
width:320px;
-
height:20px;
-
margin-top:5px;
-
line-height:20px;
-
font-size:16px;
-
color:#fff;
-
text-align:center;
-
}
-
.play
-
{
-
width:190px;
-
height:190px;
-
background:url("images/3.png");
-
border-radius:50%;
-
margin:20px auto;
-
}
-
.lrc{
-
width:300px;
-
height:280px;
-
margin:0px auto;
-
color:#ccc;
-
text-align:center;
-
overflow:hidden;}
-
.lrc p{
-
line-height:20px;}
-
#content{
-
position:relative;
-
top:0px;
-
}
-
.rotate{
-
animation:rot 5s linear infinite;}/*動畫效果*/
-
@keyframes rot{
-
from{transform:rotate(0deg)}
-
to{transform:rotate(360deg)}
-
}
-
</style>
-
</head>
-
<body>
-
<div id="phone">
-
<div class="top"></div><!--頂部-->
-
<div class="tittle">晴天</div><!--歌曲名-->
-
<div class="singer">周傑倫</div><!--作者-->
-
<div class="play" id="play"></div><!--圖片-->
-
<div class="lrc">
-
<div id="content"></div><!--存放歌詞-->
-
</div>
-
</div>
-
<audio src="music/周傑倫-晴天.mp3" id="mymusic"></audio><!--音樂-->
-
<textarea id="text" style="display:none"><!--歌詞-->
-
[ar:晴天 周傑倫]
-
[ti: 晴天 周傑倫 ]
-
[00:00.71]晴天 - 周傑倫
-
[00:28.84]故事的小黃花
-
[00:32.34]從出生那年就飄着
-
[00:35.85]童年的盪秋千
-
[00:39.41]隨記憶一直晃到現在
-
[00:42.77]rui sou sou xi dou xi la
-
[00:45.50]sou la xi xi xi xi la xi la sou
-
[00:49.41]吹着前奏望着天空
-
[00:52.60]我想起花瓣試着掉落
-
[00:56.10]為你翹課的那一天
-
[00:58.29]花落的那一天
-
[01:00.14]教室的那一間
-
[01:01.79]我怎么看不見
-
[01:03.61]消失的下雨天
-
[01:05.38]我好想再淋一遍
-
[01:09.51]沒想到失去的勇氣我還留着
-
[01:15.72]好想再問一遍
-
[01:17.47]你會等待還是離開
-
[01:24.46]刮風這天我試過握着你手
-
[01:30.18]但偏偏雨漸漸大到我看你不見
-
[01:38.50]還要多久我才能在你身邊
-
[01:44.93]等到放晴的那天也許我會比較好一點
-
[01:52.41]從前從前有個人愛你很久
-
[01:58.07]但偏偏風漸漸把距離吹得好遠
-
[02:06.44]好不容易又能再多愛一天
-
[02:12.81]但故事的最后你好像還是說了拜拜
-
[02:33.93]為你翹課的那一天
-
[02:36.39]花落的那一天
-
[02:38.13]教室的那一間
-
[02:39.84]我怎么看不見
-
[02:41.55]消失的下雨天
-
[02:43.31]我好想再淋一遍
-
[02:47.39]沒想到失去的勇氣我還留着
-
[02:53.39]好想再問一遍
-
[02:55.49]你會等待還是離開
-
[03:02.46]刮風這天我試過握着你手
-
[03:08.12]但偏偏雨漸漸大到我看你不見
-
[03:16.54]還要多久我才能在你身邊
-
[03:23.10]等到放晴的那天也許我會比較好一點
-
[03:30.49]從前從前有個人愛你很久
-
[03:36.26]但偏偏風漸漸把距離吹得好遠
-
[03:44.48]好不容易又能再多愛一天
-
[03:51.05]但故事的最后你好像還是說了拜拜
-
[03:57.65]刮風這天我試過握着你手
-
[04:01.45]但偏偏雨漸漸大到我看你不見
-
[04:04.98]還要多久我才能夠在你身邊
-
[04:08.64]等到放晴那天也許我會比較好一點
-
[04:12.34]從前從前有個人愛你很久
-
[04:15.40]但偏偏雨漸漸把距離吹得好遠
-
[04:19.05]好不容易又能再多愛一天
-
[04:22.42]但故事的最后你好像還是說了拜
-
</textarea>
-
<script type="text/javascript">
-
var oPlay=document.getElementById("play");
-
var myMusic=document.getElementById("mymusic");
-
var oText=document.getElementById("text");
-
var oCon=document.getElementById("content");
-
var mark=true;//標記音樂播放的狀態
-
oPlay.onclick= function(){
-
if(mark){
-
myMusic.play(); /*播放*/
-
this.className="play rotate";
-
mark= false;
-
} else{
-
myMusic.pause(); /*暫停*/
-
this.className="play";
-
mark= true;
-
}
-
}
-
//獲取歌詞
-
var text=oText.value.split("[");//歌詞從【切割開
-
//循環
-
var html="";
-
for(var i=0;i<text.length;i++){
-
var txt=text[i].split("]");
-
//console.log(txt[1]);
-
var times=txt[0].split(".");//從.的位置切割
-
//console.log(times);
-
var time=times[0].split(":");//從:的位置切割
-
//console.log(times);
-
var ct=time[0]*60+time[1]*1;
-
//console.log(ct);
-
//判斷txt[1]是否存在
-
if(txt[1]){
-
html+= "<p id="+ct+">"+txt[1]+"</p>"
-
}
-
}
-
oCon.innerHTML=html;
-
//獲取所有的P
-
var xP=oCon.getElementsByTagName("p");
-
var n=0;
-
//console.log(html);
-
//監聽歌曲的播放進度 歌詞同步
-
myMusic.addEventListener( "timeupdate",function(){
-
//當時間更新
-
var cur=parseInt(this.currentTime);
-
//console.log(cur);
-
if(document.getElementById(cur))
-
{
-
//先把所有的P標簽顏色改為原色
-
for(var i=0;i<xP.length;i++){
-
xP[i].style.color= "#ccc";
-
xP[i].style.fontSize= "14px";
-
}
-
//當前P標簽紅色
-
document.getElementById(cur).style.color="red"
-
document.getElementById(cur).style.fontSize="18px"
-
if(xP[n+8].id==cur){
-
oCon.style.top= -20*n+"px";
-
n++;
-
}
-
}
-
})
-
-
</script>
-
</body>
-
</html>
源碼下載:點擊這里
