怎么解决定时滚动的问题

qidizi 2008-02-25 03:13:50
我想弄歌词滚动,
但是我发现js的最小定时不能小于16ms,
也就是你想让它定时13ms执行一次那是没办法的,
就算定时了,它也会花16ms才能执行完一次,

一句歌词有w (px)宽度,
唱这句的时长是t (ms)
滚动的最小的滚动距离是1px,
但是最小的定时滚动只能达到16ms,
想让它按t / w (ms)就滚动1px怎么办?
怎么办?

当t / w < 16ms时怎么办?

改滚动距离1px成2px就会出现跳动的感觉了,所以不可用.
...全文
115 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qidizi 2008-02-29
  • 打赏
  • 举报
回复
问题是我没办法解决平滑滚动.
luojxun 2008-02-25
  • 打赏
  • 举报
回复
没必要定时小于13ms人的视觉延时就有0.1秒
  • 打赏
  • 举报
回复
呵呵!楼上直接搬代码,给答案!
支持下!
qidizi 2008-02-25
  • 打赏
  • 举报
回复
用到的代码
---------------


function getLrc(reload)
{//pi配歌词
if (typeof(currentPlaying) != "object")
{
return 0;
}

var lrcName = fso.getbasename(currentPlaying.outerText);
var title = mplayer.currentMedia.getItemInfo("title");
var Artist = mplayer.currentMedia.getItemInfo("Artist");
var lrcPath = lrcFolder.value + "\\" + lrcName + ".lrc";

if ( (!reload) && topLrc.children.length
&& (topLrc.children[0].fileName == lrcName) )
{
showLrc1();
}else if ( fso.fileexists(lrcPath)
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + title + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + Artist + "_" + title + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + Artist + "-" + title + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + Artist + " - " + title + ".lrc")
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + Artist + " " + title + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + title + "_" + Artist + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + title + "-" + Artist + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + title + " - " + Artist + ".lrc")
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + title + " " + Artist + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + lrcName.split("_")[0] + ".lrc" )
|| fso.fileexists(lrcPath = lrcFolder.value + "\\" + lrcName.split("_")[1] + ".lrc" )
)
{
var lrcArray = new Array();
lrcArray[0] = new Array('<span t="0" fileName="' + lrcName + '"><span>歌词文件名:' + lrcName, " </span></span>");

lrcToText(lrcArray, lrcPath);
}else
{
bottomLrc.style.left = "0px";
topLrc.style.left = "0px";
bottomLrc.innerText = "";
topLrc.innerText = "硬盘中没有歌词";
}
}

function lrcToText(lrcArray, lrcPath)
{//把lrc提取成可以滚动用的歌词
var fp = fso.openTextFile(lrcPath);

var lrcLine;
var lrcText = "";
var matchTime;
var lrcTime;
var offset = 0;

while (!fp.AtEndOfStream)
{
lrcLine = fp.readLine();

if (lrcLine.match(/\[ti:([^\[:\]]+)\]/gi))
{
lrcArray[0][1] = "歌曲名:" + RegExp.$1 + lrcArray[0][1] + " ";
}else if (lrcLine.match(/\[ar:([^\[:\]]+)\]/gi))
{
lrcArray[0][1] = "演唱者:" + RegExp.$1 + lrcArray[0][1] + " ";
}else if (lrcLine.match(/\[offset:([^\[:\]]+)\]/gi))
{
offset = RegExp.$1;
}else if ((matchTime = lrcLine.match(/\[\d+:\d+\.?\d+\]/g)))
{
lrcText = lrcLine.replace(/\[\d+:\d+\.?\d+\]/g,"");

while (matchTime.length)
{
lrcTime = matchTime.shift().replace(/[\[\]]/gi,"").toString().split(":");
lrcTime = lrcTime[0] * 60 + parseFloat(lrcTime[1]) + offset / 1000;
lrcArray[lrcArray.length] = new Array('<span t="' + lrcTime + '"><span>', lrcText + " </span></span>");
}
}
}

fp.close();
fp = null;

if (lrcArray.length < 3)
{
return lrcArray = null;
}

lrcArray.sort(timeSort);
lrcText = lrcArray.join("").replace(/,/g, " ");
lrcArray = null;

bottomLrc.innerHTML = topLrc.innerHTML = lrcText;
setLrcWidth();
}

function setLrcWidth()
{//设置歌词外框宽度

for (var ii=0; ii < topLrc.children.length; ++ii)
{
bottomLrc.children[ii].style.width = topLrc.children[ii].style.width = topLrc.children[ii].offsetWidth;
bottomLrc.children[ii].children[0].style.display = topLrc.children[ii].children[0].style.display = "none";
}

showLrc1();
}

function timeSort(timeA, timeB)
{//把乱xi的歌词按时间大小排序
return parseFloat(timeA[0].split('t="')[1]) - parseFloat(timeB[0].split('t="')[1]);
}

function lrcDisplay(i)
{//显示右边的歌词
bottomLrc.children[i].children[0].style.display = topLrc.children[i].children[0].style.display = "inline";
}

function lrcHidden(i)
{//隐匿已过左边的歌词
try{
bottomLrc.children[i].children[0].style.display = topLrc.children[i].children[0].style.display = "none";
}catch(e){}
}

function setLrcLeft(px)
{//设置歌词左边距达到滚动效果
lrcLeft -= px;
topLrc.style.left = bottomLrc.style.left = lrcLeft;
}


function lrcScroll()
{//定时设置歌词左边距达到滚动效果

if (lastLrcWidth < 1)
{
clearInterval(lrcScrollTimer);
}

--lrcLeft;
topLrc.style.left = bottomLrc.style.left = lrcLeft;
--lastLrcWidth;
}

function chanleLrc()
{//取消歌词滚动
clearTimeout(showLrcTimer);
clearInterval(lrcScrollTimer);
clearTimeout(scrollTimer);
}

function showLrc1()
{//调用showLRc2,lrc滚动入口,初始化
lastLrcWidth = 0;
bottomLrc.style.left = "0px";
topLrc.style.left = "0px";
lrcLeft = 0;
showLrc2(0);
}

function showLrc2(childI)
{//像素级变色滚动
lrcDisplay(childI);
var timeA = topLrc.children[childI].t * 1;
var lrcWidth = topLrc.children[childI].offsetWidth;
//document.title = topLrc.children[childI].innerText;

try{
lrcDisplay(childI + 1); //将会导致出错的一句

var timeB = topLrc.children[childI + 1].t * 1;
var tLen = parseInt((timeB - mplayer.controls.currentPosition) * 1000);
chanleLrc();

if (tLen < 1)
{
lrcHidden(childI - 2);
setLrcLeft(lrcWidth);
showLrc2(childI + 1);
}else
{
clearInterval(lrcScrollTimer);
setLrcLeft(lastLrcWidth);
lastLrcWidth = lrcWidth;

lrcScrollTimer = setInterval("lrcScroll();", tLen / lrcWidth );

showLrcTimer = setTimeout("lrcHidden(" + (childI - 2) + "); showLrc2(" + (childI + 1) + ")", tLen);
}
}catch(e)
{//出错了,最后没有对象了
scrollTimer = setInterval("setLrcLeft(1)", 85);
showLrcTimer = setTimeout("chanleLrc();"
+ "lrcHidden(" + (childI - 2) + ");"
+ "lrcHidden(" + (childI - 1) + ");"
+ "lrcHidden(" + childI + ");", 200 + lrcWidth * 85);
}
}

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧