5 min read
How to make Autotype inside of H1 span in Webflow?
- Open your Webflow project and navigate to the page where you want to add the autotype effect.
- Add an HTML Embed element to the location where you want the autotype effect to appear. You can do this by dragging an "Embed" element from the "Add Elements" panel to the desired location on your page.
- Copy and paste the following code into the HTML Embed element. This code includes the HTML structure and CSS for the effect.
- Add another HTML Embed element to your page, preferably at the bottom of your page's body, to insert the JavaScript code responsible for the autotype effect.
- Copy and paste the following JavaScript code into the new HTML Embed element:
- Publish your changes in Webflow, and you should see the autotype effect in action on your live site.
Here's a brief explanation of how the code works:
- The HTML structure contains a header with the fixed text "WE HELP" and "COMPANIES SCALE RAPIDLY", and a span element with the ID "ks-running-text" where the changing words will appear.
- The CSS hides the "break-line" span element, which is used to maintain the correct layout when only the "_" character is displayed.
- The JavaScript code defines an array of words to cycle through, and two main functions, autotype() and
- The JavaScript code defines an array of words to cycle through, and two main functions, autotype() and erase(), handle the typing and erasing of words, respectively.
- The autotype() function checks if the current word has been fully typed (including the "" character) and if so, calls the erase() function after a 1-second pause. Otherwise, it adds the next character from the current word followed by the "" character, updates the text content of the "ks-running-text" span element, and calls itself again after the specified typing speed.
- The erase() function checks if only the "" character is present. If so, it increments the currentIndex, updates the currentWord, resets currentText, and calls the autotype() function to start typing the next word. Otherwise, it removes the last character (excluding the "" character) from the current word, updates the text content of the "ks-running-text" span element, and calls itself again after the specified typing speed.
- The code also includes an event listener for the "blur" event to stop the autotype effect when the window loses focus, ensuring that the effect does not continue indefinitely when the user switches to another tab or application.
By following the steps outlined in the tutorial and implementing the provided code in your Webflow project, you should be able to add the autotype effect to your website successfully.
Subscribe to newsletter
Subscribe to receive the latest blog posts to your inbox every week.
Website pre-launch checklist
69 steps pre-launch checklist is the most complex checklist developed by years of experience in Karpi Studio.
You will find how to test and fix:
- loading speed issues,
- responsivity issues on all current devices,
- SEO issues,
- and many more.
€30 Now: €9.00
Check it now