如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里
今天來看看怎么實現炫酷的打字機效果。即把一段話一個字一個字的顯示出來。
效果圖:
實現思路:
首先規定好顯示字數的速度即settimeout執行間隔用來控制每個字之間輸出速度。再把判斷段落的總字數,循環段落總字數來實現一個字一個字的輸出。
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;
-
藍藍設計( www.lzhte.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服務