模仿QQ播放器,歌曲名超出長度,文字自動左右滾動

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE>div+js實現首尾相連循環滾動效果</TITLE>
</HEAD>


<BODY>




<br /><br /><br /><br />


<DIV id="scrollobj" style="white-space:nowrap;overflow:hidden;width:100px;">只想一生跟你(粵)走-張學友</DIV>




<script language="javascript" type="text/javascript">
<!--
var flag = true;
var total = 0;
var timeFlag =0;
function scroll(obj) {

if(flag){
total = (obj.scrollLeft)++;
}
if (obj.scrollLeft==total){
flag = false;
clearInterval(timeFlag);
setTimeout(function(){
timeFlag = setInterval("scroll(document.getElementById('scrollobj'))",35);
},2000);

}
if(0<=obj.scrollLeft<total){
if(!flag){
total = (obj.scrollLeft)--;
//alert(total+";"+obj.scrollLeft)
if(total==1){
flag = true;
total = 0;
obj.scrollLeft = 0;
clearInterval(timeFlag);
setTimeout(function(){
timeFlag = setInterval("scroll(document.getElementById('scrollobj'))",35);
},2000);
}


}
}


}
clearInterval(timeFlag);
timeFlag = setInterval("scroll(document.getElementById('scrollobj'))",35);




//-->
</script>


</BODY>
</HTML>
發佈了26 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章