What is the method for advancing the cursor to the next line in this animation?

I've created an animation that types out:

"[Your Name] blah blah"

with a typing effect. Now, I want the cursor to move to the next line and type out:

"[Your Father Name] blah blah"

I attempted to add <br>, but it types out both lines simultaneously instead of one after the other.

.typewriter h1 {
  color: black;
  font-family: monospace;
  overflow: hidden; /* Ensures content isn't revealed until animation */
  border-right: .15em solid orange; /* Typewriter cursor */
  white-space: nowrap; /* Keeps content on single line */
  margin: 0 auto; /* Provides scrolling effect as typing occurs */
  letter-spacing: .15em; /* Adjust as needed */
  animation: 
  typing 3.5s steps(40, end),
  blink-caret .75s step-end infinite;
}

/* Typing effect */
@keyframes typing {
  from { width: 0 }
  to { width: 100% }
}

/* Typewriter cursor effect */
@keyframes blink-caret {
  from, to { border-color: transparent }
  50% { border-color: orange; }
}
<div class="typewriter" class="username">
    <h1>
     [Your Name] blah blah
    </h1>
</div>

Answer â„–1

Here is a creative solution for achieving this effect:

To create the desired animation effect, you can toggle a class on your <div>.

  • The initial typewritten line is visible and has the class first typing

  • The second typewriter line is initially hidden with just the class second

A JavaScript file is used to check every 500ms if the first line's typing is complete by comparing widths:

if ($('.first').parent().width() - $('.first').innerWidth() <= 10)

This condition indicates that the child element's width is close to its parent's width.

Once the first line finishes typing (when it reaches the parent div's width), the class typing is added to trigger the animation for the second line. The class typing can be removed from the first line while ensuring the styling remains consistent.

var checking = 1;

function checkForChanges()
{
console.log($('.first').parent().width() - $('.first').innerWidth());
    if ($('.first').parent().width() - $('.first').innerWidth() <= 10) {
      //div is as big as parent
        $(".second").css("visibility", "visible");
        $(".second").addClass("typing");
        //$(".first").removeClass("typing");
    } else {
      // div is smaller/bigger than parent
    }
    
    setTimeout(checkForChanges, 500);
}

checkForChanges(checking);
.typewriter{
  width: 100%;
}

.typing {
  color: black;
  font-family: monospace;
  overflow: hidden; /* Ensures content is revealed only during animation */
  border-right: .15em solid orange; /* Typewriter cursor */
  white-space: nowrap; /* Keeps content on one line */
  margin: 0 auto; /* Provides scrolling effect */
  letter-spacing: .15em; /* Adjust spacing as needed */
  animation: 
  typing 3.5s steps(40, end),
  blink-caret .75s step-end infinite;
}

/* Typing animation */
@keyframes typing {
  from { width: 0 }
  to { width: 100% }
}

/* Typewriter cursor animation */
@keyframes blink-caret {
  from, to { border-color: transparent }
  50% { border-color: orange; }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>

<div class="typewriter" class="username">
    <h1 class="first typing">
     [Your Name] blah blah
    </h1>
    <h1 class="second" style="visibility: hidden">
    [My Name] blah blah
    </h1>
    
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The sweetalert 2 input field is unresponsive or disabled within a materializecss modal, making it impossible to type in

My modal includes a SweetAlert2 popup when I click the "add bills" button. The code for this feature is from their documentation, so I don't believe the issue lies there. However, I am experiencing a problem where the input field is not type-able and ...

Adjusting the Underline Navigation Effect with jQuery

My current setup includes a basic navbar with an up arrow that slides underneath it when a navigation title is clicked. The arrow initially rests between two nav titles, and when one of them is clicked, some text also slides in. I am looking to implement ...

Is there a way to manipulate a website's HTML on my local machine using code?

I am currently working on a project to create a program that can scan through a website and censor inappropriate language. While I have been able to manually edit the text using Chrome Dev tools, I am unsure of how to automate this process with code. I ha ...

Bootstrap component malfunctioning and not performing as expected

Currently, I am learning how to use Bootstrap and attempting to replicate the example themes found on their official website. The specific theme I am focusing on is available at this link: https://getbootstrap.com/docs/4.3/examples/pricing/ Unfortunately, ...

When an HTML input button within a table fails to trigger any jQuery function upon being clicked

I currently have a table set up with multiple rows and columns. <table style="width: 100%;" class='table_result'> <tr><td>Text</td><td>Text</td><td>Text</td><td>Text</td> ...

Tips for resolving the "Forbidden compound class names" error that occurs when trying to select an input field

As a newcomer to selenium, I am eager to start testing the login page. The text field below is where I need to input the username: <div class="WODM WNDM" data-automation-id="userName"> <div class="gwt-Label WBEM">Email Address</div><i ...

Transferring information from various HTML forms using JQuery's ajax functionality

Hello there! I have recently started learning how to use jQuery AJAX for file uploads. Currently, I am working with a simple HTML form and including JavaScript/jQuery code within it to make an AJAX request. <!DOCTYPE HTML> <html> <head> ...

What is the best way to retrieve user groups in Django?

My goal is to investigate the user groups associated with a user in Django. However, when I check the console, I encounter the message: Uncaught ReferenceError: user is not defined at 6/:643:33 The purpose of the function is to redirect the user based ...

Do additional MySql tables have an impact on the speed of searches within a MySql database?

I am in the process of considering a database redesign for my classifieds website. Currently, I have 7 different tables in the database, each corresponding to a "MAIN CATEGORY". For instance, there is a "VEHICLES" table that contains information on variou ...

Utilizing a background image in the slick slider

<div id="largeCarousel" style="display:inline-block; float:right;"> <div class="homepage-item" style="padding-bottom:52%; position:relative; box-sizing:border-box;"> <div id="largeCarouselContent" style="position:absolute ...

Leveraging the CSS-Element-Queries Library for emulating the functionality of CSS media queries

Recently, I used a nifty CSS-Element-Queries tool to perform basic element manipulations that trigger whenever the window is resized. In simple terms, my goal was to dynamically adjust an element's attribute based on the current width of the window â ...

How about a fading effect for the select box?

I'm currently working on creating a select tag that opens its options slowly with a fade in, fade out effect when the user clicks on "Actions." I've attempted to use jQuery for this feature but haven't had any luck. Here's my code: &l ...

Swap out a term in a sentence with an interactive span element in real-time

I'm struggling with a seemingly simple task, and I feel quite embarrassed that I can't seem to solve it. My goal is to identify words in a string that begin with '@' or '#' and change their color to blue. The string itself com ...

Prevent users from saving changes made to dropdown menu values (as well as other user-inputted content) using Inspect Element on the website before it

Recently, I started testing my website for bugs and stumbled upon a major issue that caught me by surprise. I never realized that changes made with Firebug or similar plugins on websites could actually be saved and implemented. Despite my efforts to preve ...

Getting the most out of fonts with Webpack sass-loader

I recently set up a custom font in my project like this: $font-path: '~@/assets/fonts/'; @font-face { font-family: 'mainFont'; font-weight: 300; font-style: normal; src: url('#{$font-path}mainFont/mainFont.eot&apos ...

Viewing a Google Charts graph upon the loading of a web page

Utilizing the Google Charts library, I have incorporated a graphic on my web page that is dynamically added using AJAX into a <div> element. To display the graph when the page loads, I have written the following code: <script type="text/ ...

Tips for deactivating the double class with jQuery

I need to implement a feature where all classes on a button are disabled if a specific class is present. I attempted to disable all classes, but it seems like I made an error somewhere. Jquery: if ($('.lgi_btn_cta_toggle').hasClass('lgi_ct ...

Create a border around the text using a strokeoutline

I'm attempting to apply an outline to text using CSS. The issue I'm facing is that the shadow doesn't work well for perfectly stroked text. Is there a way to achieve this with just CSS? Below is the code snippet I am currently using: . ...

Position an element in the middle of the range between the tallest and shortest characters

Is there a way to vertically center an element between the tallest and shortest characters of another element (preferably using just CSS, but JavaScript is also acceptable)? I want it to be aligned with the actual text content rather than the line height, ...

Is it possible to trigger a reflow prior to initiating a lengthy JavaScript operation?

Ready to face the criticism, I understand that this question has been asked many times before, and I am aware that there are likely more efficient ways to achieve what I'm trying to do... In a JavaScript function, I have a process that can take up to ...