Element flickering occurs when hovering over an element with an animation present

I'm currently working on a hover navigation, which was functioning properly until I introduced animations. Now, whenever there is an animation involving movement, it seems to flicker when hovered over.

Here is the code causing the issue. When I remove the animation I added, everything works as expected:

.hide {
  display: none;
}

.hover {
  position: absolute;
  display: block;
  width: 200px;
  height: 200px;
  background: grey;
}

.hover:hover+.hide {
  display: inline-block;
  background: #fff;
  position: absolute;
}

@keyframes animation {
  0% {
    font-size: 14px;
  }
  100% {
    font-size: 15px;
  }
}

.animationexample {
  animation: animation 1s infinite;
  position: absolute;
  top: 0;
  right: 0;
}
<p class="animationexample">Animation</p>

<p class="hover">
  Hover over this
  <p class="hide">Now hover over this</p>
</p>

Answer №1

After adding pointer-events: none to the CSS rule for .hide, I noticed that the flickering problem was resolved. It seems like the hover effect is now functioning properly as well. Hopefully, this adjustment has resolved all of the issues.

By applying the CSS property pointer-events: none to the .hide element, it ensures that the element will not intercept mouse events, allowing these events to pass through and reach elements located underneath.

.hide {
    display: none;
    pointer-events: none;
}

Answer №2

This answer is left open-ended in the hopes that someone with a deep understanding of how animation works can provide further insights and explanations.

An important observation is that the two elements are not nested, despite appearing so in the HTML layout. Your CSS correctly accounts for this by using a + selector instead of >.

When the .hide element is hovered above (in the z-direction) the .hover element, it prevents the .hover element from detecting the hover event.

Initially, when no hovering occurs, .hide is set to display: none and remains invisible without taking up any space.

When .hover is hovered over, .hide changes to display: inline and position: absolute, causing it to overlay .hover due to its position in the DOM hierarchy. This temporary overlay prevents .hover from registering the hover event until .hide reverts back to display: none and removes its absolute positioning.

The lack of flickering, even without unrelated animations, may be attributed to timing and repaint considerations within the system.

If an animation is ongoing, the system triggers a repaint as soon as the position of .hide is altered.

However, if there are no active animations, the system delays the repaint process, allowing the transition of .hide's position to occur within a single frame without causing flickering.

A clearer explanation on how CSS animations handle such scenarios would greatly benefit this discussion.

For reference, the link https://developer.mozilla.org/en-US/docs/Web/Performance/Animation_performance_and_frame_rate delves into animation sequences but overlooks cases involving changes in position and display values.

In agreement with @BrendanMorel, setting pointer-events to none effectively resolves the issue of .hide intercepting the hover events.

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 process for establishing the admin's username and password using a database table?

I recently developed a website that includes a login form for the administrator. I have set up an admin table in my database and filled it with values. However, when I attempt to log in, the password is not being recognized. Here is a snapshot of my curren ...

When hovering over the menu list, the background-color of the text area remains the same

I am facing an issue with my list menu. The hover effect changes the background color only in the box area, but not in the text area. I would like to figure out a way to make both areas change color on hover: Here is the code snippet: <div class="se ...

`Generating an ever-changing masonry layout on a website using live data`

I'm currently working on a new web project and I want to incorporate a masonry view for the images on the homepage. The plan is to host this project on Azure, using blob storage for all the images. My idea is to organize the images for the masonry vi ...

Misaligned Div Content

Check out my jsfiddle here The text inside the <div> is shifting upwards Could someone explain why this is occurring? And suggest a solution? I would truly appreciate any assistance. Thank you! ...

Enhancing Vue app with durable storage capabilities

Currently, I am delving into VueJS and have created a basic todo application. It functions effectively, but my goal is to save data locally so that it remains persistent even after the page is reloaded. The code below is a result of following some helpful ...

Unintroduced jQuery Keyup

I am currently working on a project where I am trying to incorporate an autocomplete feature into an input form. My approach involves using jQuery to trigger an AJAX call to a servlet and adding a listener on the input field for keyup events. However, it s ...

A div positioned to the left is placed beneath another div

I am faced with a design challenge involving two divs. The first div is floated left, while the second div is floated right. In order to achieve a responsive layout, I need the first div to go under the second div when the viewport changes. Both divs conta ...

"Enhance Your Form with Ajax Submission using NicEdit

Currently, I am utilizing nicEditor for a project and aiming to submit the content using jQuery from the plugin. Below is the code snippet: <script type="text/javascript"> bkLib.onDomLoaded(function() { new nicEditor().panelInstance('txt1' ...

Configuring Node.js and express.js for my personal website to showcase my projects

I am new to node.js and I'm excited to implement it on my personal website as a way to start learning. I have successfully set up the node server, but I am struggling with setting up routing using express.js. All my files are typical static files like ...

incapable of executing a rest request

Hello everyone, I am trying to make a REST call and redirect the output to a text area in HTML. Below is the code I have written for this purpose. Please review it and let me know if there are any mistakes. Additionally, could you please explain how to a ...

Sticky table header with scrolling body

I am trying to display a scrollable table list with a fixed header, but I'm having issues with the header content not displaying properly without word wrapping. Additionally, there seems to be a 1px gap above the sticky header when scrolling through t ...

Error Styling: Using CSS to Highlight Invalid Checkboxes within a Group

Is there a way to create a bordered red box around checkboxes that are required but not selected? Here is the code I currently have: <div class="fb-checkbox-group form-group field-checkbox-group-1500575975893"> <label for="checkbox-group-15005 ...

Transition in the background color of a button while the superfish menu gracefully drops down

I am currently using a customized drop down menu created with Superfish. My goal is to incorporate an independent fade-in effect for the drop down menu. The background color should change on mouseover and the drop-down box should fade in gradually. You ca ...

Integrating fresh fonts into TinyMCE's font selection choices

I recently reviewed a thread regarding Google Fonts and TinyMCE, and I have successfully added new fonts to TinyMCE in the past. However, I am currently facing an issue where I am unable to add a new font called "Samman" that I obtained from MyFonts.com. ...

"The functionality of the personalized checkbox is not working as expected

Having an issue with my custom checkbox where only the first one gets selected when I select the bottom checkbox. I suspect it might be a styling problem, but I'm unsure. I've recreated the issue in a sandbox for you to check out: https://codesan ...

When the flex-grow property is set to 1, the height of the div extends beyond the space that

Here is an example of some HTML code: .container { height: 100%; width: 100%; display: flex; flex-direction: column; padding: 10px; background-color: aqua; } .box { width: 100%; height: 100%; flex-grow: 1; background-color: cadetb ...

Tips for eliminating excess padding hidden by carousel controls

Below is the code snippet I have implemented: index.html html, body { margin: 0; padding: 0; } body { width: 100%; height: 100%; } .container { width: 100vw; height: 100vh; background-color: #fc2; } /*.container .carousel slide .carou ...

How can you combine accessibility with absolute positioning?

Have you seen our unique hamburger design? https://i.stack.imgur.com/AmT6P.png A simple click will reveal a neat popup (the class "open" is added to a div). https://i.stack.imgur.com/yPydJ.png This cool effect is achieved using fixed positioning, but i ...

The functionality of Jquery-chosen appears to be malfunctioning when applied to a select element

I am encountering an unusual issue with Jquery-Chosen. There is a multi-select box within a pop-up where the options are populated using an ajax call. Strangely, Jquery-Chosen does not seem to work on it. However, if I use a static multi-select box in the ...

Ways to position an absolute element in the middle of two CSS Grid cells

Is it possible to position an element with position: absolute between two grid cells, where half of the element is on the sidebar and the other half is on the rest of the page? The challenge arises when there is overflow set on both the sidebar and the pag ...