Further exploration of key frames in CSS

Assuming I start with:

@keyframes animateleft{from{left:-300px;opacity:0} to{left:0;opacity:1}}

Can I modify it to achieve the following effect where it jumps left to right and back as its main position?

@keyframes animateLeftJump{
from{left:-300px;opacity:0} 
to{left:0;opacity:1}
from{left:0px;} 
to{right:100px;}
from{right:100px;}
to{left:0px;}
}

Answer №1

To achieve the desired animation, it's recommended to utilize percentages when dividing the keyframe:

@keyframes my-animation{
  0%{}
  10%{}
  50%{}
  100%{}
}

By splitting the keyframe into parts, you need to determine the total duration of the entire animation for each segment to last as needed.

For instance, if you want the duration of 0 - 10% to be 3 seconds, then the complete animation should run for 30 seconds.

animation-name: my-animation;
animation-duration: 30s;

div{
  background:red;
  animation:grow 30s infinite;
  width:50px;
  height:50px;
  }
 @keyframes grow{
  10%{
  width:200px;
  height:200px;
  }
  50%{
  width:400px;
  height:400px;
  }
  100%{
  width:100%;
  height:600px;
  }
  }
<div>
</div>

Answer №2

Sorry, it is not possible to use :

@keyframes animateLeftJump{
  from{left:-300px;opacity:0} 
  to{left:0;opacity:1}
  from{left:0px;} 
  to{right:100px;}
  from{right:100px;}
  to{left:0px;}
}

Your query:

Can I divide it by 1000 times? like 0.1%{}

Yes, you can divide it but be cautious as the speed of keyframes change is high. Make sure to accurately set the animation-duration and adjust the keyframes.

div {
  width: 100px;
  height: 100px;
  background-color: #000;
  animation: test 2s infinite;
  color: #FFF;
}

@keyframes test {
  0.01% {background-color:orange }
  0.08% {background-color: blue}
  0.15% {background-color: green}
  0.20% {background-color: red}
  0.25% {background-color: skyblue}
}
<p>The changes occur so rapidly that some may go unnoticed</p>
<div>Observe the Keyframes Change Here</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

Changing the format of PHP SQL results from vertical to horizontal

Is there a way to convert the vertical table generated by the following code into a horizontal one with stylish formatting? Additionally, is it possible to display certain columns in a popup window based on query parameters using jQuery or CSS? <html&g ...

Move one div to reveal another underneath

I currently have a div housing various products that can be added by clicking the add link. Whenever the add link is clicked, an information message appears briefly before fading out after 4 seconds. This message shows up at the top of the childbox-conten ...

Tips for adjusting the size of numbers (e.g. 0, 1,4..) using CSS

I have a paragraph on my website that contains a phone number and an email address within the header section. I have styled them to be the same font-size: small, but for some reason, the phone number appears slightly larger than the email address when view ...

Dynamic background image coupled with navigation buttons

Within the realm of Bootstrap 3, I've crafted a navbar that showcases a background image alongside a series of menu items positioned below said image: The following snippet of CSS handles the background image: .navbar-fixed-bottom .navbar-collapse ...

What is the best way to make the cursor display as 'wait' while a script is running?

During the execution of a lengthy javascript function, I would like to change the cursor style to 'wait' and then revert it back to normal once the function is complete. I initially tried using the following code: document.body.style.cursor = &a ...

Progress Bar Aligned in the Middle

I am having difficulty centering the percentage total within the colored progress bar. I have attempted placing the <p> tag in various <div> tags but haven't been able to figure it out. Can someone provide assistance? ...

What is hindering the responsiveness of this HTML table?

I recently designed a schedule table that resizes properly in the browser, but when I tried to access it on my mobile phone, it didn't resize correctly. On my phone screen, half of Thursday was cut off due to the horizontal scroll. https://i.sstatic. ...

Modifying the CSS class of an element does not produce the desired effect after altering its styles using JavaScript

html: <input id="myinput" class="cinput" type="image" src="http://www.foodwater.org.au/images/triple-spiral-3-small-button.jpg"/> <br><br><br><br> <button id="s">set to visible class</button> <button id="h"> ...

Display or conceal content based on checkbox status

i am trying to create a system where content is hidden by default and only displayed when a checkbox is checked. The goal is to show the content when the checkbox is checked and hide it when unchecked, so that other content can be shown as well upon checki ...

Ways to change the CSS styles of components within App

When my app is in full screen mode, I need to increase the font size for certain components. Within my App.jsx file, I have a variable that adds the "fullscreen" class to the root DIV of the app when triggered. Instead of using a blanket approach like * ...

Changing CSS properties in React

Currently, I am working on a dynamic table component using CSS grid. My goal is to customize the grid-template-columns CSS property. I am familiar with using repeat in CSS to achieve this. However, I am facing a challenge when it comes to dynamically chang ...

The positioning of divs shifts when adjusting the width of the screen

I'm having trouble creating a design similar to the one in this image. When I adjust the browser width, two divs don't remain aligned properly. If I use float: left for both divs, they stack vertically, but the layout breaks when I resize the scr ...

Struggling to locate text within the confines of the meta viewport

So I'm new to this whole blogging thing and I wanted to make sure my site was responsive. I added the meta viewport tag, but when I tested it out on Google Chrome with different window sizes, my text just disappeared! Here's a snippet of the CSS ...

The contents within the <div> element are not appearing on the webpage

I've been attempting to design a card that performs a 3D rotation when the mouse hovers over it. While I've successfully incorporated the background and front image of the card, I'm facing an issue with adding text to it. Here is the incorr ...

JS animation triumphant

I have developed an app that utilizes a checkbox to control the appearance of an overlay on a screen. To ensure smooth transitions, I have incorporated animations into the process. #overlay{ position:absolute; height: 100vh; width: 100vw; ...

Text transitions in a gentle fade effect, appearing and disappearing with each change

I want to create a smooth fade in and out effect for the text within a div when it changes or hides. After researching on Google and Stack Overflow, I found that most solutions involve adding a 'hide' CSS class and toggling it with a custom func ...

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

Using CSS and JavaScript to hide a div element

In my one-page website, I have a fixed side navigation bar within a div that is initially hidden using the display:none property. Is there a way to make this side nav appear when the user scrolls to a specific section of the page, like when reaching the # ...

Prevent an interruption in the flow of content by keeping the line unbroken

Having an issue with a visible line break between the content of an HTML element and its :after content. The problem arises in a sortable table where a small arrow is displayed at the top. To view the problem, check out this fiddle http://jsfiddle.net/ceu ...