Simple JavaScript Typing Animation Plugin
Usage purposes: You don't (or you do not want to) have node installed globally on your machine.
Required:
Run $ docker-compose up inside the project's root directory.
To initialize Typeit plugin you need to pass two arguments:
- st - selector or DOM element
- nd - configuration object
Init example:
<h1>
<span id="typeit"></span>
</h1>
<script src="./path/to/typeit.js"></script>
<script>
new CCS.TypeIt('#typeit', {
words: [
'Sample text',
['This', 'is', 'also', 'allowed']
],
speed: 100,
delay: 900,
backwards: true,
infinity: true,
onType: function(event, word) {
// handle event
}
})
</script>
words- an array of Strings (array with pieces of words will be transformed to strings). Note: text content typed inside your DOM element will be automatically added to the beginning of the words arrayspeed- typing speed, by default95(ms)delay- delay between typeit actions, by default650(ms)letterTag- specify each letter html tag, by defaultfalse- pure textletterClass- specify each letter wrapper class, by defaultfalse- no class. Note: Works only when aletterTagis also specifiedbackwards- removes letters one by one, by defaultfalse- removes the whole wordfrugal- find a common part during (backwards) clearing letters and start typing the new word from the queue if both words begin with exact same sentences. By defaultfalse. Note: Works only ifbackwardsmode is enabled - set totrueleaveLast- leave the last word visible after finishing the whole typing loop, by defaultfalseinfinity- enable infinity type loop, by defaultfalse. Note: Option will be disabled automatically when bothinfinityandleaveLastoptions are selectedonType/onClear/onComplete- functions which are triggered during plugin lifecycle. Accepts callback function with two parameters (eventandword) as a value, by defaultfalse
We can distinguish three main events during the plugin lifecycle:
onType- triggered every time when the word is typingonClear- triggered every time when the word is clearingonComplete- triggered when typing loop is over andinfinityoption is disabled
There are available some basic unit tests which (more or less) cover some basic typeit.js functionality.
Run $yarn test inside the project's root directory to start tests.