Create a CSS-based typing animation for each line in a sequence
P粉403804844
P粉403804844 2024-03-31 17:50:29
0
1
474

<div class='screen'>
  <div class='text-container'>
    <p class='text'>A problem has been detected and system has been shut down to prevent damage to your computer.
    </p>
    <br />
    <p class='text'>IRQL_NOT_LESS_OR_EQUAL</p>
    <br />
    <p class='text'>If this is the first time you've seen this Stop error screen, restart your computer.</p>
    <p class='text'>If this screen appears again, follow these steps:</p>
    <br />
    <p class='text'>Check to make sure any new hardware or soFtware is properly installed.</p>
    <p class='text'>If this is a new installation,</p>
    <p class='text'>ask your hardware or soFtware manufacturer for any system updates you might need.</p>
    <br />
    <p class='text'>If problems continue, disable or remove any newly installed hardware or soFtware.</p>
    <p class='text'>Disable BIOS memory options such as caching or shadowing.</p>
    <p class='text'>If you need to use Safe Mode to remove or disable components, restart your computer.</p>
    <p class='text'>press F8 to select Advanced Startup options, and then select Safe Mode.</p>
    <br />
    <p class='text'>Technical information:</p>
    <br />
    <p class='text'>*** STOP: 0x0000000A /0x0000000000004A,</p>
    <p class='text'>0x0000000000000002, 0x0000000000000001, 0xFFFFF80002B37ABF</p>
    <br />
    <p class='text'>Collecting data for crash dump ...</p>
    <p class='text'>Initializing disk for crash dump ...</p>
    <p class='text'>Beginning dump of physical memory.</p>
  </div>
</div>
*{
  padding: 0;
  margin:0;
  box-sizing: border-box;
}

@keyframes typing {
  from { width: 0; }
  to { width: 100%; }
}

div.screen {
    background-color: #032f7c;

    div.text-container {
      padding: 20px;
      
      p.text {
        font-family: monospace;
        color: #ebf6ff;
        overflow: hidden;
        white-space: nowrap;
        letter-spacing: 1.5px;
        animation: typing 5s steps(90, end);
      }
    }
  }

What I want to do is display text to the user with a typing animation here, line by line, top to bottom. I've tried a lot of things but I can't find a solution other than defining a different p.text for each keyframe element. This makes my code look like spaghetti because there are 17 p.text elements. what do I do?

Here is the codepen link for this issue: https://codepen.io/mehmetguduk/pen/RwJqzpN

P粉403804844
P粉403804844

reply all(1)
P粉903969231

You need to apply the delay manually to each row. For SCSS, an example code snippet to do this is to use a @for loop and then multiply the index by the duration of the animation.

@for $i from 0 through 20 {
      p.text:nth-of-type(#{$i + 1}) {
        animation-delay: #{$i * 4}s;
      }
    }

Of course, this will require some additional tweaking to achieve perfect timing, but should give you a rough idea of ​​how to fix this problem.

Make sure your animation state is also set to both, so the text is hidden at the beginning and remains visible after the animation ends.

edit:

You can also use JavaScript to set animation delays as follows:

document.querySelectorAll('p.text').forEach((el, i) => el.style.animationDelay = `${i * 5}s`)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template