JSFiddle - React, Tailwind, and code Playground
by Droid047
HTML
<div id="MyTypedText"></div>
JavaScript
/**
* User Interface Typed Text plugin for jQuery v1.6.4 or >.
*
* Version: 1.1.0
*
* Copyright (C) 2015 Norberto Hernandez
**/
// the semi-colon before function invocation is a safety net against concatenated
// scripts and/or other plugins which may not be closed properly.
;(function($) {
/**
* @param text2Type - The text to animate.
* @param space - the amount of milliseconds between each letter being displayed.
**/
$.fn.typedText = function() {
/**
* Proccess each given argument by determining what each argument
* is referring to. Also the plugin should only allow a minimum
* of 1 argument and a max of 3.
**/
processArgs = function(args) {
//Store the number of arguments
var numOfArgs = args.length;
//Make sure that the amount of arguments is only 1-3
if(numOfArgs >= 1 && numOfArgs <= 3) {
//Set the "currentArg" & "argType" vars before the loop so it won't get initiated multiple times.
var currentArg;
var argType;
// Set the variable we're going to return at the end of the function.
// The variable will hold an object that will contain the given parameters
// if possible.
var givenArgs = {
text2Type: "",
space: 66,
callback: ""
};
/**
* Go through each argument and and check if it is valid for any
* of the necessary parameters.
**/
for(var i = 0; i < numOfArgs; i++) {
//Store the argument
currentArg = args[i];
//Store the type of the argument
argType = typeof currentArg;
//Determine what variable we should assign this argument to.
...