Is there an issue with CSS animation glitches in Chrome? Specifically referring to the width transition effect on a centrally

I recently encountered a strange issue with my centered div layer that transitions from a fixed width to 100% when scrolling down. The problem arises in Chrome and Edge on Windows 10, where certain elements like images shake and jitter during the transition, while text remains unaffected.

After researching, I found that Chrome had previous issues with flickering during transitions without hardware acceleration, but those were supposedly resolved years ago by Google. Despite this, the problem persists for me.

I attempted various workarounds to trigger hardware acceleration, but none proved successful. It appears that the shaking only occurs when transitioning a centered div with a fixed width to full width using margin: 0 auto.

Interestingly, when I tried replicating the issue on JSFiddle, it wasn't consistently reproducible on my system.

You can view the JSFiddle demo here: https://jsfiddle.net/aobrien/vc4n8ecy/

If you scroll down on the demo, you'll notice the chrome logo shaking. The issue seems more prominent on wider screens (around 1700px or higher) when the browser is at full width or scaled to 80%.

//jQuery to add sticky class when scrolling

$(window).scroll(function() {
  if ($(this).scrollTop() > 1) {
    $('.header').addClass("sticky");
  } else {
    $('.header').removeClass("sticky");
  }

});
body {
  height: 2000px;
}

.header {
  background: #335C7D;
  margin: 0 auto;
  width: 1000px;
  transition: width .6s ease;
  height: 200px;
}

.sticky {
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
  will-change: width;
}

.wrap {
  width: 1000px;
  margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="header">
    <div class="wrap">
      <img src="https://i.sstatic.net/iaYsc.png" />
      <h1> Hello World.</h1>
    </div>
  </div>
</div>

This method seemed simple for creating a full-width sticky menu with a transition effect, yet the issue persisted. Could it be related to recalculations of the centering due to the combination of margin: 0 auto and width changes?

Despite all efforts, I have not been able to find a solution or workaround for this frustrating issue.

Answer №1

Success! I believe I've stumbled upon a solution.

By simply including the CSS rule display: table; to the element utilizing the transition property, it appears that the shaking effect has been eliminated.

//Utilizing jQuery to apply the sticky class during scroll events

$(window).scroll(function() {
  if ($(this).scrollTop() > 1) {
    $('.header').addClass("sticky");
  } else {
    $('.header').removeClass("sticky");
  }

});
body {
  height: 2000px;
}

.header {
  background: #335C7D;
  margin: 0 auto;
  width: 1000px;
  transition: width .6s ease;
  height: 200px;
  display: table; /* adding this line seems to resolve the issue */
}

.sticky {
  position: fixed;
  width: 100%;
  left: 0;
  right: 0;
  will-change: width;
}

.wrap {
  width: 1000px;
  margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
  <div class="header">
    <div class="wrap">
      <img src="https://i.sstatic.net/iaYsc.png" />
      <h1> Hello World.</h1>
    </div>
  </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

What is the best way to implement a loading cursor when the Submit button is clicked?

Is there a way to incorporate a progress cursor into my code in order to notify the user to wait when they click the Submit button or the Upload Button while uploading multiple files? Below is an example of my form: <form action="" method="post" enct ...

What are the steps to restrict the scope of a <style> declaration in HTML?

Currently, I am in the process of creating a user interface for a webmail. Whenever I receive an email, I extract its content and place it within a <div> element for display purposes. However, one challenge that I am facing is that each email contain ...

Removing a single div box causes a ripple effect on another div box, despite their lack of connection

I'm struggling to remove the white box underneath the "features" section on this website (). The structure of the div is quite simple: <div class="donatenew"></div> and here's the CSS: .donatenew { width:100%; background: #f8f ...

What is the best way to create a close button using JavaScript?

I just started learning JavaScript and I want to figure out how to make the close button close the div .popup1 in the following code: https://jsfiddle.net/74hmx0vb/1 <div class='popup1' id="popup1"> <div class="containe ...

What is the best way to ensure that two contact fields are capable of adapting

Looking for a way to center two fields ("Call Us" and "Our Email") while also ensuring they are responsive on different screen sizes? The goal is to have them stack one on top of the other when viewed on a small screen. Even though inline CSS has been used ...

Navigating to a New URL in Robotframework Without Closing the Browser After Working on the Old URL

Currently, I am working on a basic project that involves launching the Chrome browser and performing operations on two different websites. After completing tasks on the first website, I need to logout and then switch over to the second website. Here is an ...

How to stop a div from shifting downwards with CSS

Within my Web Application, I have implemented HTML code that displays different texts above input fields based on certain conditions. However, the issue I am facing is that the input fields are being shifted down by the text. I want the input fields to al ...

The final row of the jQuery Autocomplete list is concealed inside the div element

I have integrated a jQuery autocomplete feature on our website, which generally works well. However, sometimes the returned rows from the autocomplete are not fully visible and appear to be hidden within the containing div. Can anyone suggest the easiest ...

Displaying iFrame Border in React Native WebView

When attempting to dynamically add YouTube videos to my React Native app, I decided to utilize a combination of WebView and iFrame due to the incompatibility of the current react-native-youtube component with RN 16+. Although this solution works, the ifram ...

Troubleshooting problems with Bootstrap's media query designs

Forgive me for asking what may seem like a basic question, but I'm struggling to understand something, I have been given design specifications with the following widths: S- 320px M - 768px L - 992px XL - 1920px However, the media queries being used ...

Wait for the jQuery UI tabs to load until the entire HTML has been rendered

I have implemented jQuery UI tabs on my website. Occasionally, when the page first loads, all the HTML content for each tab is visible before the tabs themselves appear. This causes a slight delay in positioning the content within the tabs and creates an ...

html/css - techniques for transitioning a centered image on a landing page into a navbar logo when scrolling

Creating a minimalist navbar without the use of JavaScript or custom CSS is easier than you think. <nav class="navbar navbar-expand-md navbar-light bg-faded"> <a class="navbar-brand" href="#"> <img src=&qu ...

What is the best way to filter an array in Angular?

When I type in the input field, only the list items containing my input will be displayed in the unordered list. For example, if I type "Ad", then only the list item with "Add some todos" will be shown. When I clear the input, all the list items will reapp ...

"Encountering an index error while using PHP, CSS, and AJAX

I've been struggling with this issue for the past five days, but nothing seems to be working. I have scoured through numerous posts on this topic, yet none of the solutions provided have helped me. Currently, I am using an OpenCart CMS and my goal is ...

Ways to apply CSS in jQuery using various combinators

I'm facing an issue with changing CSS using jQuery. The specific CSS line I want to modify is: .switch-vertical input ~ input:checked ~ .toggle-outside .toggle-inside { top: 40px; } My attempt at changing it looked like this: $('.switch-vertic ...

Inject colors dynamically into component

I currently have two components in my project. The first component is responsible for setting colors which are then used in the second component. However, I find it tedious to set each color individually and am looking for a more efficient solution. I am c ...

What is the process for creating two columns with an input box beneath them?

I am facing a challenge with my code. I am struggling to create the desired design where there are two columns and below them an input box that will be displayed when a button is pressed. The design I am aiming for can be viewed here: enter image descripti ...

Guide on calculating the total sum of numbers from multiple selected elements based on class within a div that has a designated id

https://i.sstatic.net/uyjPk.pngI'm currently working on a task that involves summing up the number of listeners from various servers. These values are stored within a div with the id="channel1", and each number of listeners is located in a span elemen ...

Can you align a row under its corresponding column in Bootstrap?

Hello, I'm facing a dilemma with my layout. I have a grid consisting of 2 Rows and 4 Columns (col-md-8 & col md-4 in each row). The structure is as follows: Within the container Row 1 Column 1 (md-8) Row 1 Column 2 (md-4) [Accordion] Row 2 Colum ...

Tips for adjusting the item count in mat-autocomplete

For quite some time now, I've been attempting to adjust the number of items in a mat-autocomplete without any luck. My project involves using material.angular.io Below is a snippet of my code import { Component, OnInit } from '@angular/core&a ...