What could be causing the slight pause in my CSS3 animation at each keyframe percentage range?

I'm currently working on an animation for a sailing ship, but I'm encountering some issues with its smoothness. Whenever I make changes in the @keyframes, the animation stops abruptly. The movement involves using transform:rotate(-5deg) and then switching to

5deg</code to create a wave-like effect, while also adjusting the "left" values for horizontal motion. However, the result is far from what I expected in terms of smoothness. What CSS code component am I overlooking to ensure a fluid and seamless animation?</p>

<p>Here is the code snippet:</p>

<pre><code>div {
  width: 150px;
  height: 150px;
  top: 20px;
  background-image: url('https://s-media-cache-ak0.pinimg.com/originals/c2/bb/ae/c2bbaed0207deef5775af9c01e1b31ba.jpg');
  position: relative;
  background-size: cover;
  animation: mymove 5s linear infinite alternate;
  transform: rotate(0deg);
  transform:translate3d
  transition: all;
}

@-webkit-keyframes mymove {
  from,
  20% {
    trans: -2%;
    transform: rotate(5deg)
  }
  20%,
  30% {
    left: 20%;
    transform: rotate(-5deg)
  }
  40%,
  50% {
    left: 40%;
    transform: rotate(5deg)
  }
  60%,
  70% {
    left: 60%;
    transform: rotate(-5deg)
  }
  80%,
  90% {
    left: 80%;
    transform: rotate(5deg)
  }
  90%,
  100% {
    left: 100%;
    transform: rotate(-5deg)
  }
}

Answer №1

Combining multiple percentage values like 20%, 30% { ... }, 40%, 50% { ... }, etc., will result in the same rules being applied between those steps/values, causing a slight pause in animation.

By removing one of the percentage values and keeping only the left property for the first and last, you can achieve a smoother animation.

div {
  width: 150px;
  height: 150px;
  top: 20px;
  background-image: url('https://s-media-cache-ak0.pinimg.com/originals/c2/bb/ae/c2bbaed0207deef5775af9c01e1b31ba.jpg');
  position: relative;
  background-size: cover;
  animation: mymove 5s linear infinite alternate;
  transform: rotate(0deg);
  transform:translate3d
  transition: all;
}

@-webkit-keyframes mymove {
  from,
  0% {
    left: -150px;
    transform: rotate(5deg)
  }
  20% {
    transform: rotate(-5deg)
  }
  40% {
    transform: rotate(5deg)
  }
  60% {
    transform: rotate(-5deg)
  }
  80% {
    transform: rotate(5deg)
  }
  100% {
    left: 100%;
    transform: rotate(-5deg)
  }
}
<div></div>


To optimize your CSS code, you can combine similar rules with the same property/value using the original syntax as shown below.

div {
  width: 150px;
  height: 150px;
  top: 20px;
  background-image: url('https://s-media-cache-ak0.pinimg.com/originals/c2/bb/ae/c2bbaed0207deef5775af9c01e1b31ba.jpg');
  position: relative;
  background-size: cover;
  animation: mymove 5s linear infinite alternate;
  transform: rotate(0deg);
  transform:translate3d
  transition: all;
}

@-webkit-keyframes mymove {
  from,
  0% {
    left: -150px;
  }
  20%, 60%, 100% {
    transform: rotate(-5deg)
  }
  0%, 40%, 80% {
    transform: rotate(5deg)
  }
  100% {
    left: 100%;
  }
}
<div></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

Is it possible to create a fading effect on an image using a border-radius of 50%?

Struggling with fading out an image that's circular in shape due to the border-radius: 50%. <section id="main"> <h1>Non-Important-Text</h1> <h4> it's all fun and games until you can't find a damn sol ...

Styling with CSS: Utilize flexbox to adjust the layout of two elements, ensuring they

Trying to float an image to the right side of a paragraph is proving to be more challenging than anticipated. 100px +-------------------------+ +------------+ | | | | | ...

You need to click the form submit image twice in order to make it work

Struggling to get a standard opt-in form to work with an image submit button. The script works fine with a regular submit button, but the image button requires two clicks initially and then one click after unless the page is refreshed. I believe there mig ...

Adjust transparency in Bootstrap slider with picture indicator

Currently, I am in the process of creating an HTML page featuring a Bootstrap carousel. To enhance user interaction, I have replaced the standard selector with images that, when clicked, will transition the slider to display corresponding content. In orde ...

Unable to create a clickable button within a CSS3DObject using Three.js

How can I create an interactive button on a CSS3DObject within a cube made up of 6 sides? The button is located on the yellow side, but I'm facing issues with clicking on it. Whenever I attempt to click on the button, the event.target always points to ...

Adjust tool tip text on the fly

As a beginner, I created a test table and now I want to make the tool tip text change dynamically when I hover over the table with my mouse. Ideally, I would like the tool tip text to correspond to the content of the table cell. Currently, I only have stat ...

What is the best way to extract text from multiple "div class" (html) elements in R?

My objective is to collect data from this html page in order to build a database: https://drive.google.com/folderview?id=0B0aGd85uKFDyOS1XTTc2QnNjRmc&usp=sharing One of the variables I am interested in is the price of the apartments. I have noticed th ...

Reduce the size of a webpage by 10%

Have you ever noticed that when you press Ctrl+- on any browser, the page scales down to 90% of its original size? It actually looks nicer at 90%, so I want my webpage to default to opening at 90% instead of 100%. I've tried following common approach ...

I am unable to switch my carousel to full-screen mode

I'm struggling to make the carousel fullscreen even though I've set the width to 100%. Bootstrap was used in this project. Any help would be appreciated. Thank you! <html> <head> <link href="homepage.cs ...

Angular text input with customizable placeholder text and embedded icon

Hey there, I'm looking to create a unique custom textbox that includes a text placeholder and a help icon that will display useful information in a popover. https://i.sstatic.net/Zh0IK.png When typing into the input, the textbox should have a specif ...

Encountering an issue when trying to use SVG clip-path in Safari

I'm currently experimenting with creating a unique hexagonal border around a button. My approach involves enlarging the container element by a few pixels compared to the button size and using the same clip-mask on both elements to achieve a bordered e ...

Ways to showcase a div exclusively on UC mini browser

I'm looking for help to create a script that will only display a div with the class "info-box" in UC Mini browser. This div should be hidden in all other browsers. Can someone assist me with this? <!doctype html> <html> <head> <m ...

What is causing my css elements to appear larger compared to other instances?

As someone who is not a designer, I find myself doing a lot of cutting and pasting for my side hustles. I believe many others can relate to this experience. Currently, I am working on a personal project that involves using tailwindcss, appwrite, and svelte ...

Deleting content from cells in table for all even td items

This problem has been causing me frustration; I've attempted various methods using jquery and CSS, but to no avail. Essentially, I have the following table structure: <table id="mainTable"> <thead> <tr> <th>Arrival ...

Firefox fails to render SVG animation

Currently, I'm attempting to incorporate this unique animation into my website: http://codepen.io/dbj/full/epXEyd I've implemented the following JavaScript code in order to achieve the desired effect: var tl = new TimelineLite; tl.staggerFromTo ...

Aligning Content in the Middle of a Bootstrap Column

Can anyone help me with centering the content of a bootstrap column vertically? I'm facing an issue when setting width: 100% and height: 100% for the overlay div. Any solutions? Here is an example image of what I am trying to achieve: https://i.ssta ...

Adjust the appearance of an element based on user selection from a dropdown menu under certain circumstances

I am working on creating a dropdown menu using a JavaScript array. My goal is to display a specific span element when certain options are selected. For instance, I want the span to be shown only when options "a" and "c" are selected, but not when option " ...

Align numbers vertically inside scrollbar center

I have created a program where you can input a number, and it will count from 0 to the specified number. Currently, the numbers are aligned horizontally up to 12 before starting on a new line. However, I would like the numbers to be arranged vertically fr ...

Customize checkbox and label using jQuery

I have a scenario where I have multiple checkboxes and corresponding labels. When the answer is correct, I want to change the background color of the selected checkbox and label. <input type="checkbox" id="a" class="check-with-label" /> <label fo ...

Preventing parent properties from overriding descendants is a key part of maintaining a hierarchical

I found a css file online that I'm using for a website I'm building, but I am only incorporating certain components from it. The issue is that the global styles in this css file are overriding all the global styles on my website. My solution was ...