JS實(shí)現(xiàn)簡單的鍵盤打字的效果
更新時(shí)間:2015年04月24日 10:37:21 投稿:hebedich
本文給大家分享的是使用javascript實(shí)現(xiàn)的簡單的鍵盤打字效果,十分的簡單實(shí)用,推薦給有需要的小伙伴參考下。
以代碼形式實(shí)現(xiàn)過程分析:
<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>
最新內(nèi)容: <a id = "Hotnews" href="" target="_blank"> </a>
<script language="javascript">
var NewsTime = 2000; //每條信息完整出現(xiàn)后停留時(shí)間
var TextTime = 100; //每條信息中的字出現(xiàn)的間隔時(shí)間
var newsi = 0;
var txti = 0;
var txttimer; //調(diào)用setInterval的返回值,用于取消對函數(shù)的周期性執(zhí)行
var newstimer;
var newstitle = new Array(); //以數(shù)組形式保存每個(gè)信息的標(biāo)題
var newshref = new Array(); //以數(shù)組形式保存信息標(biāo)題的鏈接
newstitle[0] = "歡迎來到我的博客"; //顯示在網(wǎng)頁上的文字內(nèi)容和對應(yīng)的鏈接
newshref[0] = "http://www.dbjr.com.cn/guihailiuli/";
newstitle[1] = "http://www.dbjr.com.cn/guihailiuli/";
newshref[1] = "http://www.dbjr.com.cn/guihailiuli/";
newstitle[2] = "博客園歡迎你哦";
newshref[2] = "http://www.dbjr.com.cn";
newstitle[3] = "ByeBye~~";
newshref[3] = "http://www.dbjr.com.cn";
function shownew(){
hwnewstr=newstitle[newsi]; //通過newsi傳遞,依次顯示數(shù)組中的內(nèi)容
newslink=newshref[newsi]; //依次顯示文字對應(yīng)的鏈接
if(txti>=hwnewstr.length){
clearInterval(txttimer); //一旦超過要顯示的文字長度,清除對shownew()的周期性調(diào)用
clearInterval(newstimer);
newsi++; //顯示數(shù)組中的下一個(gè)
if(newsi>=newstitle.length){
newsi = 0; //當(dāng)newsi大于信息標(biāo)題的數(shù)量時(shí),把newsi清零,重新從第一個(gè)顯示
}
newstimer = setInterval("shownew()",NewsTime); //間隔2000ms后重新調(diào)用shownew()
txti = 0;
return;
}
clearInterval(txttimer);
document.getElementById("Hotnews").href = newslink;
document.getElementById("Hotnews").innerHTML = hwnewstr.substring(0,txti+1); //截取字符,從第一個(gè)字符到txti+1個(gè)字符
txti++; //文字一個(gè)個(gè)出現(xiàn)
txttimer = setInterval("shownew()",TextTime);
}
shownew();
</script>
</body>
</html>
以上所述就是本文的全部內(nèi)容了,希望能夠給大家學(xué)習(xí)javascript有些幫助。
相關(guān)文章
Bootstrap modal使用及點(diǎn)擊外部不消失的解決方法
這篇文章主要為大家詳細(xì)介紹了Bootstrap modal使用及點(diǎn)擊外部不消失的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
JavaScript實(shí)現(xiàn)將UPC轉(zhuǎn)換成ISBN的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)將UPC轉(zhuǎn)換成ISBN的方法,涉及javascript字符串操作的相關(guān)技巧,需要的朋友可以參考下2015-05-05
Array, Array Constructor, for in loop, typeof, instanceOf
雖然在 JavaScript 中數(shù)組是是對象,但是沒有好的理由去使用 `for in` 循環(huán) 遍歷數(shù)組。相反,有一些好的理由不去使用 for in 遍歷數(shù)組。2011-09-09
詳解JavaScript閉包的優(yōu)缺點(diǎn)和作用
閉包是指在 JavaScript 中,內(nèi)部函數(shù)可以訪問其外部函數(shù)作用域中的變量,即使外部函數(shù)已經(jīng)執(zhí)行完畢,這種特性被稱為閉包,本文將給大家介紹一下JavaScript閉包的優(yōu)缺點(diǎn)和作用,需要的朋友可以參考下2023-09-09
在線一元二次方程計(jì)算器實(shí)例(方程計(jì)算器在線計(jì)算)
在線一元二次方程式計(jì)算器實(shí)例分享,大家參考使用吧2013-12-12

