JS實現簡單的鍵盤打字的效果,js鍵盤打字

來源:互聯網
上載者:User

JS實現簡單的鍵盤打字的效果,js鍵盤打字

以代碼形式實現過程分析:

<html><head><title>打字效果</title><meta http-equiv="Content-Type" Content="text/html;charset=gb2312" /><style type="text/css">body{  font-size:14px;  font-color:#purple;  font-weight:bolder;}</style></head><body>最新內容: <a id = "Hotnews" href="" target="_blank"> </a>  <script language="javascript">  var NewsTime = 2000;    //每條資訊完整出現後停留時間  var TextTime = 100;    //每條資訊中的字出現的間隔時間    var newsi = 0;  var txti = 0;  var txttimer;   //調用setInterval的傳回值,用於取消對函數的周期性執行  var newstimer;    var newstitle = new Array();    //以數組形式儲存每個資訊的標題  var newshref = new Array();   //以數組形式儲存資訊標題的連結    newstitle[0] = "歡迎來到我的部落格";   //顯示在網頁上的文字內容和對應的連結  newshref[0] = "http://www.bkjia.com/guihailiuli/";    newstitle[1] = "http://www.bkjia.com/guihailiuli/";  newshref[1] = "http://www.bkjia.com/guihailiuli/";    newstitle[2] = "部落格園歡迎你哦";  newshref[2] = "http://www.bkjia.com";    newstitle[3] = "ByeBye~~";  newshref[3] = "http://www.bkjia.com";    function shownew(){    hwnewstr=newstitle[newsi];    //通過newsi傳遞,依次顯示數組中的內容    newslink=newshref[newsi];     //依次顯示文字對應的連結         if(txti>=hwnewstr.length){      clearInterval(txttimer);  //一旦超過要顯示的文字長度,清除對shownew()的周期性調用      clearInterval(newstimer);       newsi++;   //顯示數組中的下一個            if(newsi>=newstitle.length){        newsi = 0;  //當newsi大於資訊標題的數量時,把newsi清零,重新從第一個顯示      }      newstimer = setInterval("shownew()",NewsTime);   //間隔2000ms後重新調用shownew()      txti = 0;        return;    }    clearInterval(txttimer);      document.getElementById("Hotnews").href = newslink;      document.getElementById("Hotnews").innerHTML = hwnewstr.substring(0,txti+1);   //截取字元,從第一個字元到txti+1個字元        txti++;  //文字一個個出現    txttimer = setInterval("shownew()",TextTime);     }  shownew();</script></body></html>

以上所述就是本文的全部內容了,希望能夠給大家學習javascript有些協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.