Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

FlowTypeWriter: Advanced Text Streaming & Typewriter Effect 🖋️

License: MIT FlowTypeWriter is a lightweight, highly customizable JavaScript library for creating an engaging typewriter (or text streaming) effect on web pages. It supports rich HTML, variable typing speeds, natural pauses, and a sleek, customizable aesthetic (including dark themes), giving your text a dynamic, "AIGC soul-like" presentation.

🚀 Preview

Experience FlowTypeWriter in action!

Animated GIF Demo:

FlowTypeWriter Demo GIF

Full Video Demo (MP4):

For a more detailed look at the features and fluidity, you can watch or download the full MP4 video:

➡️ Watch/Download flow_type_writer.mp4

(Depending on your browser and GitHub's rendering, this link might play the video directly or prompt a download.)


Live Demo: (Suggestion: Deploy this project to GitHub Pages or a similar service to provide a live preview link here!)

  • Example: [Live Demo](https://your-username.github.io/FlowTypeWriter/) (Replace your-username with your actual GitHub username)

Run Locally: Clone this repository and open index.html in your browser to see the effect with the example configuration.

✨ Features

  • Dynamic Typing Effect: Simulates natural, human-like typing.
  • Variable Speed & Pauses: Typing speed can vary randomly, with additional pauses for punctuation, creating an "AIGC soul-like" rhythm.
  • Full HTML Support: Renders HTML tags within the text as elements, not typed out character by character. Style your text with <strong>, <em>, <span> with colors, etc.
  • Highly Customizable: Control base speed, speed variance, punctuation pauses, cursor character, cursor blink speed, and an on-complete callback.
  • Modern Aesthetics: Easily styleable. The example index.html demonstrates a sleek dark theme with "high-order design sense."
  • Lightweight & Vanilla JS: No external dependencies required.
  • Easy Integration: Simple to set up and use in any web project.

🛠️ Tech Stack

  • HTML5
  • CSS3 (for styling the container and demo page)
  • Vanilla JavaScript (ES6+)

⚙️ Installation & Usage

  1. Download or Clone: Get the typewriter.js file and include it in your project. If you've cloned the repository, it's at the root.

  2. Include the Script: Add the typewriter.js script to your HTML file, typically before the closing </body> tag or in the <head> with defer.

    <script src="path/to/typewriter.js"></script>

    If typewriter.js is in the same directory as your index.html, you can use:

    <script src="typewriter.js"></script>
  3. Prepare an HTML Container: Create an HTML element where the typewriter effect will display the text.

    <div id="myTypewriter"></div>
  4. Initialize the Script: Call the streamPrintAdvanced function after the DOM is loaded, providing the target element's ID, the text to type, and optional configuration.

    document.addEventListener('DOMContentLoaded', () => {
        const myText = "Hello, <strong style='color: #00AFFF;'>world</strong>! This is FlowTypeWriter writing with an <em style='color: #2ecc71;'>AIGC soul</em>.";
        
        const typewriterOptions = {
            speed: 60,                // Base speed in ms per character
            speedVariance: 40,        // Speed variation (e.g., 40 means +/- 20ms)
            punctuationPause: 350,    // Extra pause for punctuation in ms
            cursorChar: '▋',          // Cursor character
            cursorBlinkSpeed: 500,    // Cursor blink cycle in ms
            onComplete: () => {
                console.log('Typing complete!');
            }
        };
    
        // Ensure the streamPrintAdvanced function is available globally or imported if using modules
        if (typeof streamPrintAdvanced === 'function') {
            streamPrintAdvanced('myTypewriter', myText, typewriterOptions);
        } else {
            console.error('streamPrintAdvanced function not found. Ensure typewriter.js is loaded correctly.');
        }
    });

🔧 Configuration Options

The streamPrintAdvanced function accepts three arguments: elementId, textToPrint, and an optional options object.

Parameter Type Default Description
elementId string Required The ID of the HTML element where the text will be typed.
textToPrint string Required The text string to be typed. Can include HTML tags.
options object {} An optional object for configuration.
options.speed number 70 Base typing speed in milliseconds per character.
options.speedVariance number 0 Random variance added/subtracted from base speed (e.g., 50 results in speed +/- 25ms). Humanizes typing.
options.punctuationPause number 200 Additional pause in milliseconds after typing common punctuation marks (e.g., , . ? ! ; : ()).
options.cursorChar string '▋' The character used for the blinking cursor.
options.cursorBlinkSpeed number 500 The duration of one cursor blink cycle in milliseconds.
options.onComplete function ()=>{} A callback function that executes when all text has been typed.

##🎨 Styling

The typewriter.js script injects minimal essential CSS for the cursor's blinking animation.

For advanced styling, including the dark theme, container appearance, fonts, and other visual enhancements demonstrated in the index.html example, you will need to add your own CSS. Refer to the <style> section in the provided index.html for a comprehensive example of how to achieve a "high-order design sense" and dark theme. You can adapt or expand upon this CSS to match your project's specific design requirements.

Key elements to style in your CSS:

  • The container element (e.g., #myTypewriter) for background, text color, font, padding, borders, shadows, etc.
  • Any specific HTML elements you use within the typed text (e.g., strong, em, span.highlight-blue).

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page (replace your-username/FlowTypeWriter with your actual repository path).

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT License.

A copy of the MIT License should be included in your repository in a file named LICENSE or LICENSE.md. You can easily add one on GitHub when creating the repository or add it manually. The text for the MIT license can be found at opensource.org/licenses/MIT.


This README aims to be a comprehensive guide for FlowTypeWriter. Feel free to customize it further to best suit your project!

About

FlowTypeWriter: Advanced Text Streaming & Typewriter Effect

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages