Giter Site home page Giter Site logo

dupontbertrand / jquery-teletype-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stvwhtly/jquery-teletype-plugin

0.0 2.0 0.0 37 KB

Teletype is a jQuery plugin that types out text, and then optionally deletes it, replicating human interaction.

Home Page: http://teletype.rocks/

JavaScript 100.00%

jquery-teletype-plugin's Introduction

jQuery Teletype Plugin

Teletype is a jQuery plugin that types out text, and then optionally deletes it, replicating human interaction.

Additional options provide the ability to preserve the typed text, in a console / terminal format, pause during typing and delete characters.

An online demo can be found at http://teletype.rocks.

Installation

Via bower:

bower install jquery.teletype

Manual:

<script src="jquery.js"></script>
<script src="jquery.teletype.js"></script>
<script>
	$( function() {
		$( '.type-text' ).teletype( {
			text: [ 'one', 'two', 'three' ],
			typeDelay: 0,
			backDelay: 20
		} );
	} );
</script>
...
<div class="type-text"></div>

Options

Option Default Description
text ['one','two','three'] (array) List of strings to output.
typeDelay 100 (integer) Minimum delay, in ms, between typing characters.
backDelay 50 (integer) Minimum delay, in ms, between deleting characters.
blinkSpeed 1000 (integer) Interval, in ms, that the cursor will flash.
cursor "|" (string) Character used to represent the cursor.
delay 2000 (int) Time in ms to pause before deleting the current text.
preserve false (boolean) Prevent auto delete of the current string and begin outputting the next string.
prefix "" (string) Begin each string with this prefix value.
loop 0 (int) Number of times to loop through the output strings, for unlimited use 0.
humanise true (boolean) Add a random delay before each character to represent human interaction.
callbackNext null (function) Callback function called every text item. See Callback functions below.
callbackType null (function) Callback function called every 'letter'. See Callback functions below.
callbackFinished null (function) Callback function called once everything is finished. See Callback functions below.

Methods

teletype.setCursor(string cursor)

Change the cursor value. Can be used at any time although particularly useful when combined with callback functions.

Deleting characters ~

It is possible to delete a defined number of characters then proceed with the rest of the text output.

Use ~x within the text string, where x is an integer value defining the characters to backspace.

Example, type "auti", delete 1 character and continue to type "o", resulting in the word "auto":

auti~1o^`

Pause / Delay ^

Delay typing the next character using ^x where x in an integer value of milliseconds to pause.

To pause for 2 seconds after typing the word "pause" before continuing to type:

pause^2000 more

Line Breaks \n

Line breaks can be added using \n, which are converted to <br /> during output.

Generated Markup

The following markup is used to output the teletype text.

<span class="teletype-prefix">[prefix]</span>
<span class="teletype-text">[string]</span>
<span class="teletype-cursor">[cursor]</span>

This provides the ability to customise the style of the output text in your CSS.

Callback functions

There are two callback functions available, callbackNext and callbackType.

Using the callbackNext callback

Called every time a new text item begins. Two parameters are passed back here, current and teletype.

The current object holds details of the current text and position pointers.

current = { 
	string: '', 	// The full text line being written.
	index: 0, 		// Array index of the text array.
	position: 0, 	// Character index position within the current text string.
	loop: 0 		// Current loop number, increments if settings.loop is enabled.
};

The second parameter teletype returns the teletype object itself, allowing you to easily interact with the teletyper.

Example, change the cursor when moving to the 3rd text item (index 2).

callbackNext: function( current, teletype ) {
	if ( current.index == 2 ) {
		teletype.setCursor( 'โ–‹' );
	}
}

Using the callbackType callback

Callback function called every 'letter', when either typing or deleting output.

There are three parameters used here, letter, current and teletype.

The value of letter is the text that will be written, usually a single character but can be HTML markup for special characters.

The other two parameters are the same as those used by callbackNext (see above).

callbackType: function( letter, current, teletype ) {
	if ( current.index == 2 && current.position == 13 ) {
		teletype.setCursor( '_' );
	}
}

Using the callbackFinished callback

Callback function called immediately once the teletype process is entirely finished.

The single parameter teletype returns the teletype object itself.

callbackFinished: function( teletype ) {
	alert( 'Nothing left to type!' );
}

Minification

The Minified version of this script was provided by UglifyJS 2 - an online version can be found at http://gpbmike.github.io/refresh-sf/.

jquery-teletype-plugin's People

Contributors

stvwhtly avatar marshyski avatar bredmor avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.