/* =================================================== * jqlyric.js v0.1 * shawnk@qq.com * 使用方法 * var $container=$('#lyriccontainer'); //用于显示歌词的容器对象,样式自己定义 * $container.jqlyric({ * lyric:'\ [ti:存在] \ [ar:汪峰] \ [al:存在] \ [by:Love] \ [00:00.00]汪峰 - 存在 \ [00:00.68]多少人走着却困在原地 \ [00:07.93]多少人活着却如同死去', // 歌词字符串,标准lrc文件格式 * speed:1000, // 歌词滚动间隔 (毫秒) * getPosition:function(){ // 获取当前播放位置的函数(返回秒数), 请定义外部函数,不指定本参数则默认从调用插件开始自动播放 * return position; * } * }); * =================================================== * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ========================================================== */ (function($) { var gtime=0; var lyric_listener; $.fn.jqlyric = function(options) { var opts = $.extend({}, $.fn.jqlyric.defaults, options); return this.each(function(){ var o = $.meta ? $.extend({}, opts, $this.data()) : opts; var $this=$(this); var arrLyric=new Array(); //放存汉字的歌词 var arrTime=new Array(); //存放时间 var currentLine=0; //当前活动的歌词行号 // 开始解析歌词 var lyric=o.lyric; lyric=lyric.replace(/\]\n/g,'\]\n\|\|'); lyric=lyric.replace(/\]\s\[/g,'\]\['); lyric=lyric.replace(/\]\[/g,'===='); lyric=lyric.replace(/\[/g,'\|\|\['); lyric=lyric.replace(/====/g,'\]\['); lyric=lyric.replace(/\|\|\|\|\|\|\|\|/g,'\|\|'); lyric=lyric.replace(/\|\|\|\|\|\|/g,'\|\|'); lyric=lyric.replace(/\|\|\|\|/g,'\|\|'); //将歌词解析成数组 var arrly=lyric.split('||'); for(var i=0;iarrTime[j+1]){ temp=arrTime[j]; arrTime[j]=arrTime[j+1]; arrTime[j+1]=temp; temp=arrLyric[j]; arrLyric[j]=arrLyric[j+1]; arrLyric[j+1]=temp; } } } var arrLyricObj=new Array(); for(var k=0;k=arrLyricObj[k].timeStart&&pos<=arrLyricObj[k].timeEnd){ if($("#line-current").text()!=arrLyricObj[k].lrcContent&&fadeFinish){ if(k>0){ $("#line-last span").fadeOut(1000,function(){ $("#line-last span").text(arrLyricObj[k-1].lrcContent); $("#line-last span").fadeIn(1000); }); } if(k