Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Pixel Shifting / Jumping in Firefox with CSS Transitions

The Problem:

I'm using CSS to make a card flip around and show a kitten. There is a behavior that seems to only exist in Firefox whereby it is constantly shifting / resizing the images by a few pixels. Simply hover over the card back and watch as it moves around a little after the scale animation completes, then flip the card by clicking on it to observe how the kitten readjust its position and size after the animation as well.

Again, this does not happen in Chrome nor Internet Explorer. Can anyone explain what is causing it or provide a remedy?

The Fiddle:

http://jsfiddle.net/XEDEM/1/

The Code:

$('.card').mouseover(function() {
    $(this).css({
        'transform': 'scale(1.2)',
        '-webkit-transform': 'scale(1.2)',
        'transition': 'transform 500ms',
        '-webkit-transition': '-webkit-transform 500ms'
    });
}).mouseleave(function() {
    $(this).css({
        'transform': 'scale(1)',
        '-webkit-transform': 'scale(1)',
        'transition': 'transform 500ms',
        '-webkit-transition': '-webkit-transform 500ms'
    });
}).mousedown(function() {
    $('div.back').css({
        'transform': 'perspective(1000px) rotateY(-180deg) translateZ(0)',
        '-webkit-transform': 'perspective(1000px) rotateY(-180deg)',
        'transition': 'transform 800ms ease-in-out 300ms',
        '-webkit-transition': '-webkit-transform 800ms ease-in-out 300ms'
    });
    $('.hide').show();
    $('div.front').css({
        'transform': 'perspective(1000px) rotateY(0) translateZ(0)',
        '-webkit-transform': 'perspective(1000px) rotateY(0)',
        'transition': 'transform 800ms ease-in-out 300ms',
        '-webkit-transition': '-webkit-transform 800ms ease-in-out 300ms',
        'backface-visibility': 'hidden',
        '-webkit-backface-visibility': 'hidden'
    });
});
like image 834
daveycroqet Avatar asked Jul 20 '14 20:07

daveycroqet


People also ask

How do you stop a transition in CSS?

To pause an element's transition, use getComputedStyle and getPropertyValue at the point in the transition you want to pause it. Then set those CSS properties of that element equal to those values you just got.

How are CSS transitions triggered?

Triggering transitions You can trigger CSS transitions directly with pseudo classes like :hover (activates when the mouse goes over an element), :focus (activates when a user tabs onto an element, or when a user clicks into an input element), or :active (activates when user clicks on the element).

What is Webkit transition?

-webkit-transition is a non-standard boolean CSS media feature whose value indicates whether vendor-prefixed CSS transition s are supported or not. This media feature is only supported by WebKit. The standards-based alternative is to use a @supports feature query instead.

What are CSS transitions?

CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.


1 Answers

After some ardent research, this is a known issue with Firefox's sub-pixel rendering. More obvious demonstrations of the effect can be found here and here. The phenomenon is referred to as "pixel snapping" and it occurs rather frequently in Firefox's animation, particularly at the conclusion of a transition.

The solution, which is also proposed in the Bugzilla thread, is to add rotate(0.0001deg) to the scaling transform. This greatly reduces the effect but does not entirely eliminate it. However, it is the best I can hope for, so I'm accepting it as the answer.

like image 66
daveycroqet Avatar answered Nov 05 '22 23:11

daveycroqet