CSS Animation - Content starts to move after it has already appeared on the page

Currently, I have been delving into CSS animations with keyframes on my own. My goal is to create an animation where a small square drops down, then a rectangle extends from the left side of that square. Following this, some text appears after around 8 seconds. Next, the rectangle retreats back into the smaller square from the right side, and the smaller square moves upwards disappearing into 'thin air'. The purpose of this animation is to serve as an alert notification when someone follows me on Twitch TV during my livestream. For an example of my progress so far, you can check out this JSFiddle. Strangely, the content does not appear before the animation on JSFiddle, yet it does occur on the alert service I use. Here is a link to their tester, so you can see exactly what I mean.

Here's the HTML CODE:

<html>

<head>
  <title>GR412 Twitch Follower Alert</title>
  <link href="Twitch\followeralert.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body>
  <div class="follower-container">

    <div class="left-square-container">

    </div>

    <div class="right-retangle-container">

      <div class="header">
        <span class='keyword name'>{name}</span> is now following you!
      </div>

    </div>

  </div>

</body>

</html>

The CSS CODE:

@keyframes slideInFromAbove {
  0% {
    transform: translateY(-100%);
  }

  100% {
    transform: translateY(0);
  }
}

@keyframes slideInFromTheLeft {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(0);
  }
}

@keyframes slideInFromBelow {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(100%);
  }
}

@keyframes slideInFromTheRight {
  0% {
    transform: translateX(0);
  }

  100% {
    transform: translateX(100%);
  }
}

.follower-container {
  display: flex;
  font-family: 'Roboto';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.left-square-container {
  width: 75px;
  height: 75px;
  background: #313131;
  animation: 1s 1s 1 slideInFromAbove;
}

.right-retangle-container {
  width: 500px;
  height: 75px;
  background: #212121;
  animation: 1s 2s 1 slideInFromTheLeft;
}

.header {
  font-size: 24px;
  color: #ffffff;
  text-align: center; /*vertical alignment of text*/
  position: relative; /*horizontal alignment of text*/
  top: 50%; /*horizontal alignment of text*/
  transform: translateY(-50%); /*horizontal alignment of text*/
  margin: 10px,
    10px,
    10px,
    10px; /*GOT TO HERE, THIS COULD BE CAUSING TWITCHING*/
}

.keyword:not(.user_message) {
  color: #0d47a1;
}

However, I've encountered a few issues with my implementation. Firstly, the content displays before the animation sequence initiates. I want the screen to start empty and then execute the animations in the intended order - first dropping the square, followed by the protruding rectangle, and finally displaying the text. These elements need to remain visible for 8 seconds before another animation hides them as outlined in the initial description.

The second issue is that when the rectangle protrudes, it starts from the left edge of the square instead of the right edge as intended. This overlap disrupts the effect I'm aiming for.

I've referenced an existing question on Stack Overflow about css3 transition animation on load?, which provided some guidance but doesn't fully address my specific requirements.

Any assistance or clarity on these matters would be greatly appreciated. Should anything be unclear, please do let me know.

Note: If the second link isn't functional, kindly inform me so I can rectify it promptly.

Thank you, GR412.

Answer №1

One concern is setting the initial placement styles for the content.

Another issue to address is using

position: relative; z-index: /*some value*/
to properly layer the content.

Don't forget to include animation-fill-mode: forwards to apply the end styles of @keyframes.

I have adjusted the timing and you can view the changes in this plnkr link. Make sure to read the CSS comments included.

Calculating percentages might be necessary, so consider developing a formula that can incorporate variables for scss/less/sass usage.

CSS notes:

/*
to calculate these percentages:

([seconds of portion of animation] x 100)/[total seconds of animation]

1)  slideInFromAbove starts
2)  slideInFromTheLeft starts
3)  slideInFromTheLeft ends
4)  slideInFromAbove ends


slideInFromAbove:  
  1)  slide down
  2)  hold 
  2)  slide up


slideInFromTheLeft:
  1)  slide right
  2)  hold
  3)  slide left


*/

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 appearance of dotted points changes when they are printed on paper

Check out this customized printable application form that allows users to easily input their information and print it. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Custom Printout</title> ...

Using a single name to target multiple input fields

I currently have multiple input fields with prices: <input type="text" name="price[]" value="100"> <input type="text" name="price[]" value="50"> <input type="text" name="price[]" value="10"> <input type="text" name="price[]" value="90 ...

Steps for adjusting menu link color after being clicked

I am attempting to modify the background color of visited links. Below is my header code: echo ('<ul>'); echo('<li><a href="'.$FromPage.'">Back</a></li>'); echo('<li><a href="Tal ...

Header and Footer with auto-sizing Body that scrolls

My structure consists of a Header, Body, and Footer <div id="my-element"> <div id="header">...</div> <div id="body"> ... </div> <div id="footer">...</div> </div> Currently, the element with the ...

Trouble with Firebase import despite successful installation

I attempted to create a basic website to gain knowledge about Firebase 9, but I am facing issues when trying to import firebase files. I have searched for tutorials on configuring firebase, but they either do not address my problem or are based on older v ...

Move objects on the webpage by dragging and dropping them

My goal is to create a website with drag-and-drop functionality for elements, similar to Wordpress widgets. Users should be able to easily add text boxes to different areas on the site by simply dragging and dropping them. If necessary, they can also choos ...

Is there a way to verify if a specific combination of keys has been pressed using JavaScript?

Currently, I am creating a software application that requires the integration of custom hotkeys. These hotkeys need to be chosen by the user and stored for future use. For instance, if the user selects CTRL + M, how can I save this combination and trigge ...

CSS for Positioning Elements Side by Side Using Absolute Positioning

I'm having trouble figuring out how to position balloons like the ones shown in this image: <div class="red_frame"> <img src="https://i.sstatic.net/54SMF.png" class="r_over"/> <img src="https://i.sstatic.net/54SMF.png" ...

Automatically populate a div with content from a file

As I am completely new to the world of HTML, I find myself in need of quickly putting together something for work just as a proof of concept. I apologize if this question has been answered previously, but honestly, I wouldn't even know how to start se ...

Having trouble with the postcss-import grunt plugin?

Here is the layout of my project: my_project |-- css | -- main.css |-- css-dev | -- main.css |-- node_modules | -- bootstrap | -- dist | -- css | -- bootstrap.css |-- package.json `-- Gruntfile.js The contents of my Gr ...

Can anyone share tips on how to effectively center navbar link items with Bootstrap?

I recently tried to center the navigation links on my website using Bootstrap. I followed the instructions on the w3schools documentation and also watched a YouTube video for additional guidance. Both resources suggested adding the justify-content-center c ...

Incrementing numbers with jQuery append autoincrement

I am working with a dynamic list of input fields, each one with a unique incremental name. Here's an example structure... <input type="text" name="values[0]" value="some text"> <input type="text" name="values[1]" value="some other text"> ...

Is Ruby on Rails featured in Designmodo's Startup Framework Kit?

I'm curious if the Startup Framework Kit from Designmodo can be seamlessly incorporated into my Ruby on Rails project. While I've had success integrating their Flat-UI-Pro using a gem, I haven't come across one for the Startup Framework yet. ...

Ensuring stackable columns are centrally aligned using justify-content-center

My goal is to create a responsive layout with x columns that display 3 columns per row on lg screen sizes, aligned using justify-content-between. When the screen size is smaller than lg, all x columns should stack vertically and be aligned using justify-co ...

Styling elements in CSS to position the form button outside of the table enclosed within the form

I'm attempting to position a form button outside the table shown below, using float or another method: <form action="./deleteentry.php" method="post"> <?php foreach ($dbr as $var) { ?> <tr> ...

Arranging items in the final row of a flexbox

, I am seeking a solution that goes beyond the repetitive ones provided before. I need to find a more efficient way to achieve my desired outcome based on the code snippet below. In examining the code, it's clear that the first row accommodates 6 ele ...

"Endowed with improper dimensions, the BootStrap collapse feature

Yesterday, I posted about an issue with BootStrap and panel collapsables causing graph sizes to become distorted. The post was locked because there was no accompanying code. I have now created a code snippet for you all to see the exact problem I am facing ...

Stop iFrame from inheriting parent CSS styles

Is there a way to prevent an iFrame object from inheriting CSS properties from the main page? Specifically: I have created an iFrame object in my main class, and I want to adjust the opacity of the main page without affecting the iFrame. However, when I ...

The functionality of a pop-up window is not compatible with Google Maps

I recently implemented a script on my webpage that triggers a popup window every time the page is loaded. Here's how the script looks: <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>ColorBox de ...

Does the 'a' HTML tag secretly trigger window.location.assign?

Being relatively new to the online world, I have a simple question in mind. Imagine that I have a very basic a tag in my HTML: <a href="www.google.com"> Click me </a> What actually happens when I click on this link? Does the browser simply ...