如果您想訂閱本博客內(nèi)容,每天自動發(fā)到您的郵箱中, 請點這里
今天來看看怎么實現(xiàn)炫酷的打字機效果。即把一段話一個字一個字的顯示出來。
效果圖:
實現(xiàn)思路:
首先規(guī)定好顯示字數(shù)的速度即settimeout執(zhí)行間隔用來控制每個字之間輸出速度。再把判斷段落的總字數(shù),循環(huán)段落總字數(shù)來實現(xiàn)一個字一個字的輸出。
js代碼:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
theCharacterTimeout = 50;
-
-
-
-
-
theNewsNum = document.getElementById("incoming").children.AllNews.children.length;
-
theAddNum = document.getElementById("incoming").children.AddNews.children.length;
-
totalNum =theNewsNum+theAddNum;
-
-
-
-
-
-
-
-
-
-
if(CurrentPosion<theNewsNum){
-
-
-
-
-
-
-
if(CurrentPosion>=totalNum||CurrentPosion>=1){
-
-
-
-
if(theCurrentLength != theNewsText.length){
-
-
-
-
-
-
-
-
function setupNextNews(){
-
-
theCurrentNews = theCurrentNews % theNewsNum;
-
theNewsText = document.getElementById("AllNews").children[theCurrentNews].children.Summary.innerText;
-
theTargetLink = document.getElementById("AllNews").children[theCurrentNews].children.Summary.children[0].href;
-
-
document.all.hottext.href = theTargetLink;
-
-
-
function setupAddNews() {
-
-
theCurrentNews = theCurrentNews % theAddNum;
-
theNewsText = document.getElementById("AllNews").children[theCurrentNews].children.Summary.innerText;
-
theTargetLink = document.getElementById("AllNews").children[theCurrentNews].children.Summary.children[0].href;
-
-
document.all.hottext.href = theTargetLink;
-
-
-
-
-
-
if((theCurrentLength % 2) == 1){
-
-
-
-
-
-
document.all.hottext.innerHTML = theLeadString + theNewsText.substring(0,theCurrentLength) + myWidget + theSpaceFiller;
-
-
setTimeout("runTheTicker()", theCharacterTimeout);
-
-
-
-
document.all.hottext.innerHTML = theLeadString + theNewsText + theSpaceFiller;
-
-
setTimeout("runTheTicker()", theNewsTimeout);
-
-
window.onload=startTicker;
-
藍藍設(shè)計( www.li-bodun.cn )是一家專注而深入的界面設(shè)計公司,為期望卓越的國內(nèi)外企業(yè)提供卓越的UI界面設(shè)計、BS界面設(shè)計 、 cs界面設(shè)計 、 ipad界面設(shè)計 、 包裝設(shè)計 、 圖標定制 、 用戶體驗 、交互設(shè)計、 網(wǎng)站建設(shè) 、平面設(shè)計服務