- 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.
- 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 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.