打字效果

来源:互联网 发布:mysql bit 对应java 编辑:程序博客网 时间:2024/04/28 04:35
  1. <SCRIPT language=JAVAscript>
  2.     // ------ 定义全局变量
  3.     var theNewsNum;
  4.     var theAddNum;
  5.     var totalNum;
  6.     var CurrentPosion=0;
  7.     var theCurrentNews;
  8.     var theCurrentLength;
  9.     var theNewsText;
  10.     var theTargetLink;
  11.     var theCharacterTimeout;
  12.     var theNewsTimeout;
  13.     var theBrowserVersion;
  14.     var theWidgetOne;
  15.     var theWidgetTwo;
  16.     var theSpaceFiller;
  17.     var theLeadString;
  18.     var theNewsState;
  19.     function startTicker(){
  20.         // ------ 设置初始数值
  21.         theCharacterTimeout = 50;//字符间隔时间
  22.         theNewsTimeout = 2000;//新闻间隔时间
  23.         theWidgetOne =  "_";//新闻前面下标符1
  24.         theWidgetTwo =  "-";//新闻前面下标符
  25.         theNewsState = 1;
  26.         theNewsNum = document.getElementById("incoming").children.AllNews.children.length;//新闻总条数
  27.         theAddNum = document.getElementById("incoming").children.AddNews.children.length;//补充条数
  28.         totalNum =theNewsNum+theAddNum;
  29.         theCurrentNews = 0;
  30.         theCurrentLength = 0;
  31.         theLeadString = " ";
  32.         theSpaceFiller = " ";
  33.         runTheTicker();
  34.     }
  35.     // --- 基础函数
  36.     function runTheTicker(){
  37.         if(theNewsState == 1){
  38.             if(CurrentPosion<theNewsNum){
  39.                 setupNextNews();
  40.             }
  41.             else{
  42.                 setupAddNews();
  43.             }
  44.             CurrentPosion++;
  45.             if(CurrentPosion>=totalNum||CurrentPosion>=1){
  46.                 CurrentPosion=0;//最多条数不超过num_gun条
  47.             }
  48.         }
  49.         if(theCurrentLength != theNewsText.length){
  50.             drawNews();
  51.         }
  52.         else{
  53.             closeOutNews();
  54.         }
  55.     }
  56.     // --- 跳转下一条新闻
  57.     function setupNextNews(){
  58.         theNewsState = 0;
  59.         theCurrentNewstheCurrentNews = theCurrentNews % theNewsNum;
  60.         theNewsText = document.getElementById("AllNews").children[theCurrentNews].children.Summary.innerText;
  61.         theTargetLink = document.getElementById("AllNews").children[theCurrentNews].children.Summary.children[0].href;
  62.         theCurrentLength = 0;
  63.         document.all.hottext.href = theTargetLink;
  64.         theCurrentNews++;
  65.     }
  66.     function setupAddNews() {
  67.         theNewsState = 0;
  68.         theCurrentNewstheCurrentNews = theCurrentNews % theAddNum;
  69.         theNewsText = document.getElementById("AllNews").children[theCurrentNews].children.Summary.innerText;
  70.         theTargetLink = document.getElementById("AllNews").children[theCurrentNews].children.Summary.children[0].href;
  71.         theCurrentLength = 0;
  72.         document.all.hottext.href = theTargetLink;
  73.         theCurrentNews++;
  74.     }
  75.     // --- 滚动新闻
  76.     function drawNews(){
  77.         var myWidget;
  78.         if((theCurrentLength % 2) == 1){
  79.             myWidget = theWidgetOne;
  80.         }
  81.         else{
  82.             myWidget = theWidgetTwo;
  83.         }
  84.         document.all.hottext.innerHTML = theLeadString + theNewsText.substring(0,theCurrentLength) + myWidget + theSpaceFiller;
  85.         theCurrentLength++;
  86.         setTimeout("runTheTicker()", theCharacterTimeout);
  87.     }
  88.     // --- 结束新闻循环
  89.     function closeOutNews(){
  90.         document.all.hottext.innerHTML = theLeadString + theNewsText + theSpaceFiller;
  91.         theNewsState = 1;
  92.         setTimeout("runTheTicker()", theNewsTimeout);
  93.     }
  94. window.onload=startTicker;
  95. </SCRIPT>
  96. <a href="" id="hottext"></a>
  97. <div id=incoming style="DISPLAY: none;float:left">
  98.     <div id=AllNews >
  99.             <div id=0>
  100.             <div id="Summary" style="border:1px solid red">
  101.                 <a href="http://p.dvbbs.net/dispbbs-11-0-1-20932-0-0-0" target="_blank"><font><b>众望所归 动网PHP 2.0正式发布</b></font></a>
  102. <a href="http://p.dvbbs.net/" target="_blank"><font color="red"><b>动网论坛PHP官方站点</b></font></a>           </div>
  103.             <div id=NewsLink  ></div>
  104.         </div>
  105.         </div>
  106.     <div id=AddNews height="25"></div>
  107. </div>