javascript寫的一個模擬閱讀小說的程序
更新時間:2014年04月04日 11:14:14 作者:
這篇文章主要介紹了用javascript寫了一個模擬閱讀小說的程序,需要的朋友可以參考下
復制代碼 代碼如下:
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<head>
<title></title>
<script type="text/javascript">
function Reader(content, cID, stopID, continueID) {
this.conLoad = document.getElementById(cID);
this.stopBtn = document.getElementById(stopID);
this.continueBtn = document.getElementById(continueID);
this.content = content;
this.index = 0;
var t = this;
this.stopBtn.onclick = (
function () {
return function () {
t.stopReader(t);
};
})(t);
this.continueBtn.onclick = (
function () {
return function () {
t.continueReader(t);
};
})(t);
}
Reader.prototype = {
startReader : function () {
var t = this;
t.toId = setInterval(function () {
if (t.content[t.index]) {
t.conLoad.innerHTML += t.content[t.index];
}
t.index++;
if (t.content.length == t.index) {
clearInterval(t.toId);
t.conLoad.innerHTML += "【未完待續(xù)】";
}
}, 200);
},
stopReader : function (t) {
t.flag = true;
clearInterval(t.toId);
},
continueReader : function (t) {
if (t.flag)
t.startReader();
t.flag = false;
}
};
var content = "蒙古親王僧格林沁慓悍勇猛,他率領的軍隊向來號稱能征慣戰(zhàn),八旗兵、綠營他都看不上眼,更何況那些臨時招募的練勇??善褪沁@些他眼中的烏合之眾,這些年來在江南戰(zhàn)果累累,最終攻下了江寧,奪得了對太平軍作戰(zhàn)的全勝。" +
"相反地,他的蒙古鐵騎在與捻軍的角逐中常常打敗仗,相形之下,昔日的聲威銳減。這個一代天驕的后裔,對曾氏兄弟和湘軍窩著一肚皮無名怒火。" +
"湘軍進江寧后,打劫財富,屠城縱火,又放走幼天王,朝野謗讟四起,物議沸騰,僧格林沁聽了十分得意,趕緊打發(fā)富明阿以視察滿城為由,去江寧實地了解。誰料曾國荃一嚇一賄征服了富明阿,江寧將軍回去后向僧格林沁作了假匯報。";
//頁面加載完成之后執(zhí)行。
window.onload = function () {
new Reader(content, "content", "btnStop", "btnContinue").startReader();
};
</script>
<body>
<div id='content'></div>
<div id='operate'><input type='button' id='btnStop' value='stop'/><input type='button' id='btnContinue' value='continue'/></div>
</body>
</html>
相關文章
KnockoutJS 3.X API 第四章之數(shù)據(jù)控制流foreach綁定
這篇文章主要介紹了KnockoutJS 3.X API 第四章之數(shù)據(jù)控制流foreach綁定的相關資料,需要的朋友可以參考下2016-10-10
asp錯誤 '80040e21' 多步 OLE DB&nbs
今天在寫asp入庫操作的時候提示Microsoft OLE DB Provider for ODBC Drivers 錯誤 80040e21 多步 OLE DB 操作產(chǎn)生錯誤,請檢查每個 OLE DB 狀態(tài)值,經(jīng)測試時函數(shù)定義文件沒有加載導致類型不對,所以無法入庫2023-05-05

