javascript之水平横向滚动歌词同步的应用


Posted in Javascript onMay 07, 2007

参考地址:http://aboutplayer.com

var lrc0, lrc1, lrc2; 
moveflag = false; 
var top, bottom; 
var lrcobj; 
var lrctop; 
predlt = 0; 
curdlt = 0; function lrcClass(tt) 
{ 
  this.inr = []; 
  this.oTime = 0; 
  this.dts = -1; 
  this.dte = -1; 
  this.dlt = -1; 
  this.ddh; 
  this.fjh; 
  if(/\[offset\:(\-?\d+)\]/i.test(tt)) 
    this.oTime = RegExp.$1/1000; 
  tt = tt.replace(/\[\:\][^$\n]*(\n|$)/g,"$1"); 
  tt = tt.replace(/\[[^\[\]\:]*\]/g,""); 
  tt = tt.replace(/\[[^\[\]]*[^\[\]\d]+[^\[\]]*\:[^\[\]]*\]/g,""); 
  tt = tt.replace(/\[[^\[\]]*\:[^\[\]]*[^\[\]\d\.]+[^\[\]]*\]/g,""); 
  tt = tt.replace(/<[^<>]*[^<>\d]+[^<>]*\:[^<>]*>/g,""); 
  tt = tt.replace(/<[^<>]*\:[^<>]*[^<>\d\.]+[^<>]*>/g,""); 
  while(/\[[^\[\]]+\:[^\[\]]+\]/.test(tt)) 
  { 
    tt = tt.replace(/((\[[^\[\]]+\:[^\[\]]+\])+[^\[\r\n]*)[^\[]*/,"\n"); 
    var zzzt = RegExp.$1; 
    /^(.+\])([^\]]*)$/.exec(zzzt); 
    var ltxt = RegExp.$2; 
    var eft = RegExp.$1.slice(1,-1).split("]["); 
    for(var ii=0; ii<eft.length; ii++) 
    { 
      var sf = eft[ii].split(":"); 
      var tse = parseInt(sf[0],10) * 60 + parseFloat(sf[1]); 
      var sso = { t:[] , w:[] , n:ltxt } 
      sso.t[0] = Math.round((tse-this.oTime)*1000)/1000; 
      this.inr[this.inr.length] = sso; 
    } 
  } 
  this.inr = this.inr.sort( function(a,b){return a.t[0]-b.t[0];} ); 
  for(var ii=0; ii<this.inr.length; ii++) 
  { 
    while(/<[^<>]+\:[^<>]+>/.test(this.inr[ii].n)) 
    { 
      this.inr[ii].n = this.inr[ii].n.replace(/<(\d+)\:([\d\.]+)>/,"%=%"); 
      var tse = parseInt(RegExp.$1,10) * 60 + parseFloat(RegExp.$2); 
      this.inr[ii].t[this.inr[ii].t.length] = Math.round((tse-this.oTime)*1000)/1000; 
    } 
    lrcbc1.innerHTML = "<font>"+ this.inr[ii].n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/%=%/g,"</font><font>") +" </font>"; 
    var fall = lrcbc1.getElementsByTagName("font"); 
    for(var wi=0; wi<fall.length; wi++) 
      this.inr[ii].w[this.inr[ii].w.length] = fall[wi].offsetWidth; 
    this.inr[ii].n = lrcbc1.innerText; 
  } 
  this.overtop = function() 
  { 
    var ii; 
    for(ii=this.inr.length-1; ii>0 && this.inr[ii].t[0]>ffbb; ii--){} 
    top = ii; 
  } 
  this.run = function(tme) 
  { 
    if(tme<this.dts || tme>=this.dte) 
    { 
      var ii; 
      for(ii=this.inr.length-1; ii>=0 && this.inr[ii].t[0]>tme; ii--){} 
      if(ii<0) return; 
      this.ddh = this.inr[ii].t; 
      this.fjh = this.inr[ii].w; 
      this.dts = this.inr[ii].t[0]; 
      this.dte = (ii<this.inr.length-1)?this.inr[ii+1].t[0]:aboutplayer.currentMedia.duration; 
      if(!movable) 
      { 
        lrctop = 140; 
        lrcoll.style.pixelTop = 140; 
        lowlight(lrcbox1); 
        this.overtop(); 
        overbottom(); 
        for(var wi=1; wi<=this.inr.length; wi++) 
        { 
          eval("lrcbox"+wi).innerText = this.inr[wi-1].n; 
          eval("lrcbc"+wi).innerText = this.inr[wi-1].n; 
        } 
        movable = true; 
      } 
      if(this.dlt>0) lowcolor(eval("lrcbc"+this.dlt)); 
      clearTimeout(lrc2); 
      if(this.dlt==ii-1) 
      { 
        predlt = this.dlt+1; 
        if(!ptms && predlt>0) 
        { 
          eval("lrcbc"+predlt).filters.alpha.opacity = 100; 
          eval("lrcbc"+predlt).style.width = "100%"; 
          highcolor(0,this.dte-this.dts); 
        } 
        toposition(1,this.dte-this.dts); 
      } 
      if(ii-this.dlt>1 || ii-this.dlt<=-1) 
      { 
        if(this.dlt>=0) lowcolor(eval("lrcbc"+(this.dlt+1))); 
        if(this.dlt==-1 || ii==0) 
        { 
          jumpto(ii-this.dlt-1); 
          toposition(1,this.dte-this.dts); 
        } 
        else 
          jumpto(ii-this.dlt); 
      } 
      if(this.dlt>=0) lowlight(eval("lrcbox"+(this.dlt+1))); 
      this.dlt = ii; 
      curdlt = ii; 
      if(!drdc) highlight(eval("lrcbox"+(this.dlt+1))); 
      if(drdc) 
      { 
        curlowcolor(eval("lrcbc"+(this.dlt+1))); 
        curhighcolor(0,this.dte-this.dts); 
      } 
    } 
    if(klok) 
    { 
      var bbw = 0; 
      var ki; 
      for(ki=0; ki<this.ddh.length && this.ddh[ki]<=tme; ki++) 
        bbw += this.fjh[ki]; 
      var kt = ki-1; 
      var sc = ((ki<this.ddh.length)?this.ddh[ki]:this.dte) - this.ddh[kt]; 
      var tc = tme - this.ddh[kt]; 
      bbw -= this.fjh[kt] - tc / sc * this.fjh[kt]; 
      if(bbw>eval("lrcbox"+(this.dlt+1)).offsetWidth) 
        bbw = eval("lrcbox"+(this.dlt+1)).offsetWidth; 
      eval("lrcbc"+(this.dlt+1)).style.width = Math.round(bbw); 
    } 
  } 
  lrcbox1.innerText = "www.aboutplayer.com"; 
} 
function overbottom() 
{ 
  if(aboutplayer.currentMedia.duration>0) 
  { 
    var ii; 
    for(ii=lrcobj.inr.length-1; ii>0 && lrcobj.inr[ii].t[0]-ffbb>=aboutplayer.currentMedia.duration; ii--){} 
    bottom = ii; 
  } 
  else 
    setTimeout("overbottom()",10); 
} 
function jumpto(nline) 
{ 
  lrctop -= 20*nline; 
  lrcoll.style.top = lrctop; 
} 
function toposition(step,dur) 
{ 
  if(moveflag) return; 
  lrcoll.style.top = lrctop--; 
  if(step<20) 
  { 
    step++; 
    setTimeout("toposition("+step+","+dur+");",dur*50); 
  } 
} 
function highcolor(step,dur) 
{ 
  if(moveflag) return; 
  eval("lrcbc"+predlt).filters.alpha.opacity = 100-(step++)*10; 
  if(step<10) 
    lrc1 = setTimeout("highcolor("+step+","+dur+");",dur*100); 
} 
function curhighcolor(step,dur) 
{ 
  if(moveflag) return; 
  eval("lrcbc"+(curdlt+1)).filters.alpha.opacity = (step++)*10; 
  if(step<10) 
    lrc2 = setTimeout("curhighcolor("+step+","+dur+");",dur*100); 
} 
function highlight(lid) 
{ 
  lid.style.color = "#00FF00"; 
} 
function lowcolor(lid) 
{ 
  clearTimeout(lrc1); 
  lid.style.width = 0; 
  lid.filters.alpha.opacity = 100; 
} 
function curlowcolor(lid) 
{ 
  lid.filters.alpha.opacity = 0; 
  lid.style.width = "100%"; 
} 
function lowlight(lid) 
{ 
  lid.style.color = "#0080C0"; 
} 
function lrcrun(m) 
{ 
  lrcobj = new lrcClass(m); 
  lrc0 = setInterval("try {lrcobj.run(aboutplayer.controls.currentPosition+ffbb)} catch(hh){}",10); 
} 
MakeMovable(lrcollbox); 
function MakeMovable(element) 
{ 
  element.attachEvent("onmousedown",onmousedown);  
  element.attachEvent("onmouseup",onmouseup); 
  element.attachEvent("onmousemove",onmousemove); 
  flagmove = false; 
  var s_y, o_y; 
  curpot = 0; 
  function onmousedown() 
  { 
    if(event.button!=1 || moveflag || !movable || !type || bottom==0) {flagmove = true; return;} 
    clearTimeout(lrc0); 
    if(curdlt>0) lowcolor(eval("lrcbc"+curdlt)); 
    lowcolor(eval("lrcbc"+(curdlt+1))); 
    lowlight(eval("lrcbox"+(curdlt+1))); 
    if(lrcoll.style.pixelTop>120-top*20) lrcoll.style.top = 120-top*20; 
    if(lrcoll.style.pixelTop<120-bottom*20) lrcoll.style.top = 120-bottom*20; 
    s_y = event.clientY; 
    o_y = lrcoll.style.pixelTop; 
    element.style.cursor = "n-resize"; 
    element.setCapture(); 
    moveflag = true; 
  } 
  function onmousemove() 
  { 
    if(event.button!=1 || !moveflag || flagmove) return; 
    var offy = event.clientY-s_y; 
    if(o_y+offy<=120-top*20 && o_y+offy>=120-bottom*20) lrcoll.style.top = o_y+offy; 
    if(o_y+offy>120-top*20) lrcoll.style.top = 120-top*20; 
    if(o_y+offy<120-bottom*20) lrcoll.style.top = 120-bottom*20; 
    var pot = Math.floor((lrcoll.style.pixelTop-120)/-20); 
    if(pot!=curpot) 
    { 
      lowlight(eval("lrcbox"+(curpot+1))); 
      curpot = pot; 
      highlight(eval("lrcbox"+(curpot+1))); 
    } 
  } 
  function onmouseup() 
  { 
    if(!moveflag || flagmove) {flagmove = false; return;} 
    if(aboutplayer.playState==3) 
    { 
      if(lrcoll.style.pixelTop<=120-top*20 && lrcoll.style.pixelTop>100-top*20) 
        lrcobj.dte = -1; 
      else 
        lrcobj.dte = lrcobj.inr[Math.floor((lrcoll.style.pixelTop-120)/-20)-1].t[0]; 
      if(lrcobj.inr[Math.floor((lrcoll.style.pixelTop-120)/-20)].t[0]-ffbb<0) 
        aboutplayer.controls.currentPosition = 0; 
      else 
        aboutplayer.controls.currentPosition = lrcobj.inr[Math.floor((lrcoll.style.pixelTop-120)/-20)].t[0]-ffbb; 
      lrcobj.dlt = Math.floor((lrcoll.style.pixelTop-120)/-20); 
      lrctop = lrcoll.style.pixelTop; 
    } 
    else 
    { 
      lowlight(eval("lrcbox"+(curpot+1))); 
      highlight(eval("lrcbox"+(curdlt+1))); 
      lrcoll.style.top = o_y; 
    } 
    lrc0 = setInterval("try {lrcobj.run(aboutplayer.controls.currentPosition+ffbb)} catch(hh){}",10); 
    element.releaseCapture(); 
    element.style.cursor = "hand"; 
    moveflag = false; 
  } 
}
Javascript 相关文章推荐
Javascript将string类型转换int类型
Dec 09 Javascript
jQuery自定义事件的简单实现代码
Jan 27 Javascript
setinterval()与clearInterval()JS函数的调用方法
Jan 21 Javascript
jQuery+slidereveal实现的面板滑动侧边展出效果
Mar 14 Javascript
js钢琴按钮波浪式图片排列效果代码分享
Aug 26 Javascript
JS实现选中当前菜单后高亮显示的导航条效果
Oct 15 Javascript
JS小数运算出现多为小数问题的解决方法
Jun 02 Javascript
自学实现angularjs依赖注入
Dec 20 Javascript
jquery.form.js异步提交表单详解
Apr 25 jQuery
Angular异步变同步处理方法
Aug 13 Javascript
微信小程序实现展示评分结果功能
Feb 15 Javascript
vue在线动态切换主题色方案
Mar 26 Javascript
javascript之ESC(第二类混淆)
May 06 #Javascript
通过Unicode转义序列来加密,按你说的可以算是混淆吧
May 06 #Javascript
使用正则替换变量
May 05 #Javascript
又一个小巧的图片预加载类
May 05 #Javascript
清华大学出版的事半功倍系列 javascript全部源代码
May 04 #Javascript
用js实现的抽象CSS圆角效果!!
May 03 #Javascript
学习jquery必备 api中英文对照的chm手册 下载
May 03 #Javascript
You might like
php操作JSON格式数据的实现代码
2011/12/24 PHP
php中session与cookie的比较
2015/01/27 PHP
PHP和MySql中32位和64位的整形范围是多少
2016/02/18 PHP
thinkPHP框架可添加js事件的分页类customPage.class.php完整实例
2017/03/16 PHP
PHP操作Redis数据库常用方法示例
2018/08/25 PHP
Javascript实现带关闭按钮的网页漂浮广告代码
2014/01/12 Javascript
分享纯手写漂亮的表单验证
2015/11/19 Javascript
详解AngularJS中$http缓存以及处理多个$http请求的方法
2016/02/06 Javascript
JavaScript判断数字是否为质数的方法汇总
2016/06/02 Javascript
JS模拟的Map类实现方法
2016/06/17 Javascript
浅谈js原生拖放
2016/11/21 Javascript
微信小程序 PHP后端form表单提交实例详解
2017/01/12 Javascript
jQuery实现字体颜色渐变效果的方法
2017/03/29 jQuery
JS身份证信息验证正则表达式
2017/06/12 Javascript
webpack中CommonsChunkPlugin详细教程(小结)
2017/11/09 Javascript
Vue组件通信的四种方式汇总
2018/02/08 Javascript
axios 处理 302 状态码的解决方法
2018/04/10 Javascript
Vue作用域插槽slot-scope实例代码
2018/09/05 Javascript
haskell实现多线程服务器实例代码
2013/11/26 Python
在Python中使用判断语句和循环的教程
2015/04/25 Python
python3实现网络爬虫之BeautifulSoup使用详解
2018/12/19 Python
python使用Plotly绘图工具绘制散点图、线形图
2019/04/02 Python
python移位运算的实现
2019/07/15 Python
python利用JMeter测试Tornado的多线程
2020/01/12 Python
TensorFlow 显存使用机制详解
2020/02/03 Python
解决Keras 自定义层时遇到版本的问题
2020/06/16 Python
用Python制作mini翻译器的实现示例
2020/08/17 Python
美国奢侈品购物平台:Orchard Mile
2018/05/02 全球购物
一月红领巾广播稿
2014/02/11 职场文书
仓库主管岗位职责
2014/03/02 职场文书
会计专业导师推荐信
2014/03/08 职场文书
中学清明节活动总结
2014/07/04 职场文书
119消防日活动总结
2014/08/29 职场文书
上班离岗检讨书
2014/09/10 职场文书
商场营业员岗位职责
2015/04/14 职场文书
2015年信息中心工作总结
2015/05/25 职场文书