Skip to content

A simple javascript tool to easily add typeout effects to your webpage

License

Notifications You must be signed in to change notification settings

Momo8289/typeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

typeout

A simple javascript tool to easily add typeout effects to your webpage typeout

Usage

Using jsdelivr: <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>

Or, download typeout.js (or the minified version) and include it in your document: <script src="./typeout.js"></script>

Examples

Add a one-time typeout effect

<html lang="en">
<body>
    <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>
    <h1>Written with <span id="span"></span></h1>
    <script>
        let span = document.getElementById("span")
        typeOut("Javascript", span)
    </script>
</body>
</html>

Change the delay between characters to 500ms

<html lang="en">
<body>
    <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>
    <h1>This one is typed out <span id="span"></span></h1>
    <script>
        let span = document.getElementById("span")
        typeOut("slowly", span, {charDelay: 500})
    </script>
</body>
</html>

Cycle through a list of words

<html lang="en">
<body>
    <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>
    <h1>Written with <span id="span"></span></h1>
    <script>
        let span = document.getElementById("span")
        let words = ["Javascript", "HTML", "CSS"]
        cycleWord(words, span)
    </script>
</body>
</html>

Change the delay between characters to 500ms, and the delay between words to 1500ms

<html lang="en">
<body>
    <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>
    <h1>Written with <span id="span"></span></h1>
    <script>
        let span = document.getElementById("span")
        let words = ["Javascript", "HTML", "CSS"]
        cycleWord(words, span, {charDelay: 500, cycleDelay: 1500})
    </script>
</body>
</html>

Only cycle through the words once, and do not loop

<html lang="en">
<body>
    <script src="https://cdn.jsdelivr.net/gh/Momo8289/typeout/typeout.min.js"></script>
    <h1>Written with <span id="span"></span></h1>
    <script>
        let span = document.getElementById("span")
        let words = ["Javascript", "HTML", "CSS"]
        cycleWord(words, span, {loop: false})
    </script>
</body>
</html>

Reference

typeOut(string, element, options={})

Options:

Name Value Default
charDelay Delay between typed out characters in milliseconds 100
caret Boolean specifying whether or not to show a blinking caret character false
caretBlinkInterval How fast the caret blinks in milliseconds 500

cycleWord(strings, element, options={})

Options:

Name Value Default
charDelay Delay between typed out characters in milliseconds 100
cycleDelay Delay to wait after typing out a word before going to the next in milliseconds 1000
loop Whether or not to loop after going through all string in the array true
caret Boolean specifying whether or not to show a blinking caret character false
caretBlinkInterval How fast the caret blinks in milliseconds 500