1文字ずつ表示
JSのページを作りました
http://www.x-shenwu.net/~home_page/js/
//--------------------------------------------------------------------// // 前処理 //--------------------------------------------------------------------// document.body.innerHTML = ""; // body要素を白紙にする document.body.style.fontSize = "200px"; // body要素のfontサイズ変更 //--------------------------------------------------------------------// // systemオブジェクト //--------------------------------------------------------------------// var system = { text : 'こんにちは'.split(''), // 1文字ずつ表示する文字列 i : 0, // 表示する文字番号 clear_id : undefined, // setIntervalを解除するid typing : function(){ // 文字を表示する関数 document.body.innerHTML += this.text[this.i]; this.i++; if( this.i >= this.text.length ){ clearInterval( this.clear_id ); } } }; //--------------------------------------------------------------------// // system.typingを500ミリ秒ごとに実行 //--------------------------------------------------------------------// system.clear_id = setInterval( function(){ system.typing(); }, 500 );
ここまでくると、こうしたほうがベターなんすかね。
//--------------------------------------------------------------------// // 前処理 //--------------------------------------------------------------------// document.body.innerHTML = ""; // body要素を白紙にする document.body.style.fontSize = "200px"; // body要素のfontサイズ変更 //--------------------------------------------------------------------// // systemオブジェクト //--------------------------------------------------------------------// var system = { text : 'こんにちは'.split(''), // 1文字ずつ表示する文字列 i : 0, // 表示する文字番号 clear_id : undefined, // setIntervalを解除するid typing : function(){ // 文字を表示する関数 document.body.innerHTML += this.text[this.i]; this.i++; if( this.i >= this.text.length ){ clearInterval( this.clear_id ); } }, start : function(){ // system.typingを500ミリ秒ごとに実行 this.clear_id = setInterval( function(){ system.typing(); }, 500 ); } }; //--------------------------------------------------------------------// // system.start()実行 //--------------------------------------------------------------------// system.start();