Tips for avoiding background image movement during transitions

How can I prevent the background image from jumping effect during animation looping? What I have already attempted:

  • Switching animation type from transition to position change (left: 0 -> left: -100%)
  • Replacing the background image with a background gradient, but the result remains the same

DEMO HERE

<button class="loader">
  <span>Loader</span>
</button>
@keyframes sliding {
  from {
    transform: translateX(0%);
  }
  to {
    transform: translateX(-50%);
  }
}


body {
  padding: 32px;
}

.loader {
  width: 224px;
  box-sizing: border-box;
  padding: 14px;
  border: none;
  border-radius: 2px;
  background-color: tomato;
  position: relative;
  overflow: hidden;
  pointer-events: none;
}
.loader:after {    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
  background-color: tomato;
    background-image: url("data:image/svg+xml,%3Csvg width='210' height='59' viewBox='0 0 210 59' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cmask id='mask0' mask-type='alpha...
    color: white;
    background-repeat: repeat-x;
    animation: sliding 1.75s linear infinite;
    will-change: transform;
  }
.loader span {
  line-height: 20px;
  font-size: 16px;
  color: white;
}

Answer №1

If you want to create a repeating background animation, you can define it with the following keyframes and adjust the speed by setting the duration between 60-120s based on your preferences.

@keyframes sliding {
  from {
    background-position: 0 0;
  }
/*adjust width values for right to left or left to right movement*/
  to {
    background-position: -10000px 0;
  }
}

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

Troubleshooting issue with JQuery AJAX loading Bootstrap Dropdowns

I have a website on GitHub Pages that uses Bootstrap, but I'm having issues with the drop-down menu in the navbar. Sometimes it works and sometimes it doesn't. I am using $("#nav").load("url"); to load the navbar so that I can make changes and ha ...

Firefox failing to interpret nested element background

I'm facing an unusual problem with Firefox while developing a menu that has a maximum of three levels. The issue seems to be isolated to Firefox as everything works perfectly in Chrome. When I click on 'First Level Menu', a ul opens with two ...

relocate the image with an identical filename stored in the variable

Having trouble moving an image to a new position when clicking on its small thumbnail. I've attempted using jquery's find() function but it doesn't seem to be working... $('#slide1_controls img').click(function (event){ var sr ...

Tips for creating two lines of text within one line using CSS

My explanation skills are not the best. I have the words "Tasty Burger" stacked on top of each other, but I want them to be on a single line. .footer-container { margin: 25px 0; display: flex; gap: 3rem; align-items: center; justif ...

Storing input field values in JavaScript using the onchange event handler.Would you like a different revision

I am looking to calculate the area by multiplying width and height entered into input fields, and then display the result. Any guidance would be greatly appreciated. Thank you! Here is my current code. const width = document.querySelector("#width"); con ...

"Customizing the properties of an Angular Material mat-slide-toggle: A step-by-step

<mat-slide-toggle>Slide Me!</mat-slide-toggle> https://i.stack.imgur.com/p1hzD.png https://i.stack.imgur.com/aCzs1.png Is it possible to customize the toggle-thumb-icon to increase its length and position it at the end of the bar? ...

There is an irritating 5px gap between the divs in the Avada WordPress theme. While using margin-top: -5px helps to reduce this spacing, padding-top: -5

Struggling to remove a persistent 5px whitespace on my website eternalminerals.com See the issue highlighted in this screenshot: Trying to eliminate the whitespace by adjusting margins in Google Chrome, but unable to apply styles to Avada shortcodes: &l ...

Box-free calendar dash component

Encountering an issue within my application dashboard, here's a direct screenshot: https://i.stack.imgur.com/sEMrM.png The problem is that the Calendar days are extending beyond the borders of the calendar box. To implement this, I simply utilized ...

How can CSS grid be used to move a particular <td> element?

Currently, I am working on creating a dynamic table using CSS grid and I am looking to slightly adjust the left-most <th> and <td>. I am uncertain about how to move a specific element within a <table>. My goal is to achieve a layout simi ...

Tips for centering a video vertically within a cell

I need assistance with aligning a video in the center of a fixed height cell while hiding the overflow at the top and bottom. Here is what I have so far: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td height ...

Tips on adjusting the scrollbar color with CSS

Check out my jsfiddle here I am attempting to modify the color of the scrollbar, but unfortunately it is not working as expected. This is the CSS code I am using: .flexcroll { scrollbar-face-color: #367CD2; scrollbar-shadow-color: #FFFFFF; ...

Can anyone suggest a more efficient approach to handling variations using CSS?

Within the message component, there are currently only two variants available: error and success. This project is built using vue3 script setup and utilizes SCSS for styling. <script setup lang="ts"> defineOptions({ name: 'Notificat ...

When using CSS column-fill auto, the printed page breaks are disregarded

The column-fill:auto property functions by filling one complete column before moving on to the next. .two-column { column-count: 2; column-fill: auto; } In Chrome, this behavior is consistent while viewing on screen, but when printing and encounterin ...

Why doesn't the z-index of child elements function properly when their fixed parents share the same z-index value?

I have utilized jsfiddle to replicate my problem. My goal is to position .top .inside above .bottom .inside. I am aware that z-index only functions within its respective position type, for example fixed and absolute do not share the same z-index level. How ...

What's the reason behind CSS transitions starting with a black background?

When I apply a transition to the heart, it inexplicably turns black at the start of the animation before displaying the intended gradient effect. Below is the code snippet: .heart { font-size: 2.5rem; padding-right: 2rem; } .heart:hover ...

Update to the viewport meta tag in iOS 7

Anyone experiencing problems with the viewport tag after updating to iOS7? I've noticed a white margin on the right side of some sites. Adjusting the initial scale to 0.1 fixed it for iPhone but made it tiny on iPad 3, which is expected due to the low ...

Attach a floating div to multiple elements throughout a webpage

Looking for the optimal method to place a div in various locations on a webpage while anchoring it from the bottom left. The div should be able to be attached to any element on the page for relative positioning, specifically intended for a tooltip. Each ...

Issue with vertical alignment in form input text area not functioning properly

Need some help aligning inputted text with the top of a textarea on an HTML form. I've scoured forums for solutions, but no luck so far. I attempted using: textarea{ vertical-align:top;} and input["textarea"]{ vertical-align:top;} Tried adding ...

How to retrieve an element by its class using JavaScript and Jquery while implementing a

I am working on creating a quiz example using Jquery, but I am facing some challenges when trying to manipulate CSS classes with hover in Jquery. .right{ background-color: white; } .wrong { background-color: white; } .right:hover { background-color ...

Guide to modifying the text color of a Primefaces/jqPlot line chart:

I've implemented a basic JSF line chart with PrimeFaces (using jqPlot library) in my project: <p:lineChart id="linear" value="#{team.chart}" title="Lap Times" xaxisLabel="Lap" yaxisLabel="Time ...