Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS + Opacity change on Hover + Flickering

Tags:

css

opacity

hover

I am trying to achieve a very simple thing: change opacity of a table row on hover.

Unfortunately, it doesn't work very good, because if I hover in and out very fast, sometimes the opacity change is too slow and it seems like the colors are flickering. This flickering doesn't happen when I hover in and out kinda slow.

I made an example so you know what I mean:

http://jsfiddle.net/yfhTW/2/

Is this behavior a browser bug or is something wrong with my code? And can it be fixed somehow? I have tried to use a Jquery script instead of doing the opacity change via CSS, but the results are the same :/

like image 715
r0skar Avatar asked Sep 28 '11 11:09

r0skar


4 Answers

In case the affected element is already translated (and thus, the fix by kizu is not applicable) make sure to set -webkit-backface-visiblity:

-webkit-transform-style: preserve-3d;
-webkit-backface-visibility: hidden;
like image 98
Max Avatar answered Sep 16 '22 21:09

Max


Ha, it's almost the same problem the webkit sometimes have. So, I've tried to emulate the fix for webkit (the one with -webkit-transform: translateZ(0)), but using the 2D transform, and it worked!

So, it seems like just adding -moz-transform: rotate(0); to the elements that are affected by flickering solves the problem: http://jsfiddle.net/kizu/yfhTW/4/

like image 41
kizu Avatar answered Nov 20 '22 03:11

kizu


Try to add the border: 1px solid transparent; to the element (not to :hover pseudoclass). It worked for me.

like image 5
Bartłomiej Semańczyk Avatar answered Nov 20 '22 03:11

Bartłomiej Semańczyk


For people coming here who have an image with an opacity that isn't 1, and have a similar flicker, make sure you set background-color:white; on the image! I know this doesn't resolve the question at hand but it is a similar problem.

.post img { opacity:.8; background-color:white; }
.post:hover img { opacity:1; }
like image 3
Jacob Raccuia Avatar answered Nov 20 '22 05:11

Jacob Raccuia