Home
About
Blog
Media Gallery

AutoWrite


Automatic writing with JavaScript. Code and working example below.

Code:
Example Usage:
==============
- HTML: <div id="AutoText1" style="display:none">
          <span id="AutoText1_txt"></span>
          <span id="AutoText1_cur">_</span>
        </div>
  - JS: document.getElementById('AutoText1').style.display = 'block';
        setTimeout("WriteMsg('AutoText1_txt', '"+ WriteText1 +"')", WriteSpeed);
        setInterval("ShowCursor('AutoText1_cur')", CursorSpeed);
*/

// Configuration.
var CursorSpeed = 500;
var CursorActive = false;
var WriteSpeed = 50;
var WriteText1 = ""+
	"thronic.com is a pure back-end for private development and services. "+
	"Feel free to send me an e-mail on the address above if you want to reach me.[BR][BR]"+
	"Have a nice day![BR][BR]"+
	":)";

// void ShowCursor(string elem);
function ShowCursor(elem) {
	var cur = document.getElementById(elem).style;
	if (cur.visibility == 'visible')
		cur.visibility = 'hidden';
	else
		cur.visibility = 'visible';
}

// WriteMsg(string elem, string msg);
function WriteMsg(elem, msg) {
	if (msg != '') {
		var msg_arr = msg.split('');
		var WritePause = 0;
		var NextVal = msg_arr.shift();
		var docElem = document.getElementById(elem);
		
		docElem.innerHTML += NextVal;
		msg = msg_arr.join('');
		WritePause = 0;
		
		while (msg.substr(0,4) == '[BR]') {
			docElem.innerHTML += '<br>';
			msg = msg.substr(4);
			WritePause = 1000;
		}
		
		if (NextVal == '.' || NextVal == '?' || NextVal == '!' || NextVal == ',') {
			if (msg.substr(0,1) == ' ')
				WritePause = 1000;
		}
		
		setTimeout("WriteMsg('"+elem+"','"+msg+"')",WriteSpeed+WritePause);
	}
}

Click on me for a working example!


Original Post: Jan 28th, '22 00:51 CET.
Updated: Jan 28th, '22 00:52 CET.

Tags: JS Script