the background image shivering with movement

While experimenting with some animations, I encountered a small issue: When trying to animate a div that has an image as its background, the image appears to shake, especially when expanding and shrinking the div from the center. Is there a way to prevent this from happening? Or is there a simpler method to animate it smoothly? Thank you in advance.

HTML

<div class = 'button'>
  <div class = 'background'></div>
</div>

CSS

.button {
  border : 5px solid black;
  border-radius : 50%;
  height : 150px;
  width : 150px;
  animation : bigger 2s ease-in-out 0s infinite;

}
.background{
  height : 100%;
  width : 100%;
  background : url('https://image.flaticon.com/icons/svg/69/69434.svg') no-repeat;
  background-size : 90%;
  background-position : center;

}
@keyframes bigger {
  0% {
    height : 150px;
    width : 150px;
  }
  100%{
    margin-left : -5px;
    margin-top : -5px;
    height : 160px;
    width : 160px;
  }

You can see an example of the issue on CodePen: https://codepen.io/pen/

Answer №1

It seems like the issue may be related to how browsers render frames. Adjusting the timing could resolve this issue. Consider using transform: scale(x.x) instead. You can find more information on this in the following pen.

@keyframes bigger {
  0% {
    transform: scale(1)
  }
  100%{
    transform: scale(1.1)
  }
}

https://codepen.io/pen/

Answer №2

When it comes to size and timing in animations, there is a particular issue with the frames jumping back to 0. To prevent this, you can utilize

animation-direction: alternate-reverse
in your code. However, the animation may not appear as shaky with this modification.

If you want to delve deeper into this topic, you can explore more on w3schools

.button {
  width: 150px;
    height: 150px;
    position: relative;
    animation-iteration-count: infinite;
  
  border : 5px solid black;
  border-radius : 50%;
  animation : example 1s ease-in-out 0s infinite alternate-reverse;
 
}
.background{
  height : 100%;
  width : 100%;
  background : url('https://image.flaticon.com/icons/svg/69/69434.svg') no-repeat;
  background-size : 90%;
  background-position : center;

}
@keyframes example {
  0% {
    margin-left : 0;
    margin-top : 0;
    height : 150px;
    width : 150px;
  }
  100%{
    margin-left : -5px;
    margin-top : -5px;
    height : 170px;
    width : 170px;
  }
<div class = 'button'>
  <div class = 'background'></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

Don't conceal the :after and :before elements when using CSS custom checkboxes

I have created my own custom checkboxes using this CSS code: input[type="checkbox"]{ display: none; } .checkbox{ position: relative; width: 60px; height: 19px; background-color: green; border-radius: 10px; } .checkbox input[type="checkbox"] + ...

What is the best way to customize the color of the border and icon in an outlined MaterialUI input field

I'm a newcomer to materialUI and I have a question regarding customizing an outlined input field with an icon. Due to my dark background, I need the icon, border, and text color to be lighter, such as grey. Can someone please advise on the materialUI ...

The dropdown div does not activate when the image is clicked

When the image in the simple dropdown is clicked, it fails to activate the dropdown feature. This issue was encountered while working on a Shopify project, making it challenging to troubleshoot. To demonstrate the problem, I have re-created the scenario i ...

CSS styles may not be consistently displayed or may vanish after being initially implemented

The colors and background remain unchanged. In previous projects, everything ended up falling apart Refreshing the page with F5 or CTRL + F5 does not make a difference. When using Open Live Server in VS Code, it initially shows the changes being applied b ...

no visible text displayed within an input-label field

Currently, I have started working on a multi-step form that is designed to be very simple and clean. However, I am facing an issue where nothing is being displayed when I click on the next arrow. I am puzzled as to why it's not even displaying the te ...

Interactive website powered by a dynamic database system and featuring HTML pages

I am currently working on a project involving a cutting-edge dynamic database driven website where users can engage by posting, commenting, liking, and more. I have been contemplating the idea of using HTML pages instead of PHP pages. Essentially, wh ...

The sidebar scrolling feature seems to be malfunctioning, as only the page scrolling functionality is currently

I'm currently working on a webpage that features a sidebar, along with other elements as shown below: https://i.sstatic.net/gf7dX.png In this design, the Your Friends section represents the sidebar. However, I have noticed that when I hover over the ...

What causes a custom element to suddenly crumble?

I am attempting to create a custom field that can display either an SVG or a Canvas, but the rendering is not as expected. I anticipate two boxes that are 400 pixels wide and 300 pixels high, however, they appear to collapse in an unusual manner. How can I ...

Utilizing pop-up info boxes

After thoroughly reviewing the documentation on Imagemapster's website and browsing several posts, I am still struggling to get the tooltips working correctly. I attempted to share my HTML and JS code on jsfiddle.com without success, so I have provide ...

Using React Material UI to implement a button function that triggers a file picker window

I have a customized Material UI button component that I want to use for selecting files from my computer upon clicking. However, my attempt to achieve this by nesting the <Button></Button> within a <label> associated with an <input typ ...

Why is my Datalist control not showing up in ASP.NET?

For the past few days, I've been working on dynamically generating labels using a DataList in ASP.NET code. Despite confirming that the data is being pulled into the datasource and seeing the control display correctly in the HTML code 'design&apo ...

`Unable to activate label function in HTML`

As I dabble around with HTML and CSS, I've been experimenting with creating a custom file selection button. I came across a method on the internet that involves hiding the original button and superimposing a new one over it using the following code: ...

Tips on stopping Bootstrap Modal from opening when element within trigger is clicked?

I've configured my table rows to trigger a bootstrap modal upon click. However, I have an issue with the select box in each row allowing user selection of status options. Is there a way to prevent the modal from opening when the select box is clic ...

Utilizing inter-process communication in Electron to establish a global variable from the renderer process

renderer.js ipcRenderer.sendSync('setGlobal', 'globalVarName').varInner.varInner2 = 'result'; main.js global.globalVarName = { varInner: { varInner2: '' }, iWontChange: ' ...

Unlocking the potential of resizable bootstrap table columns in React

Currently utilizing a bootstrap table <div class="table-responsive"> <table class="table table-bordered"> <thead> <tr> <th>#</th> <th>Table heading</th> </tr> < ...

What is the best way to set up a loop for displaying Chat Bubbles?

Is there a way to create a loop for chat bubbles? I want them to appear on the right when I send a message and on the left when the chat partner replies. How can I implement this loop? This is the code I currently have: <div class="Webview"> &l ...

JavaScript Image Swap

I tried implementing this script but it didn't work for me. I'm not sure what to do next, so I'm reaching out for help. The script is at the top of the page, followed by a picture with an id that I'd like to change when a button below i ...

core.js:15723 ERROR TypeError: Unable to access the 'OBJECT' property because it is undefined

Whenever I attempt to run this function, I encounter an issue. My goal is to retrieve the latitude and longitude of an address from Google's API. This error message pops up: core.js:15723 ERROR TypeError: Cannot read property 'geometry' of ...

"Enhance your website design with a navbar that seamlessly blends with the background color

Question 1: I have a requirement for my navbar to affix overlay on top of the background color and image of the div (top-banner). Currently, when I scroll down, the background color overlays my navbar affix instead. How can I ensure that my navbar sta ...

sending live video from a Python server to a browser-based client

Is there a way to stream a video from a python server to an HTML page web client (Node.js)? In my Node.js web project, I am currently using Python to write frames and JavaScript to read them. However, I am facing limitations with both frame rate and resol ...