Image shifting/jumping after CSS transition effect with scale transform in Firefox

后端 未结 4 1908
清歌不尽
清歌不尽 2021-02-20 04:37

I have a problem in latest Firefox browser version 34 (system: Windows 7, screen width: 1600px). I made effect with zooming images (in some container) after hov

相关标签:
4条回答
  • 2021-02-20 05:00

    On the link that you provided, http://demo.qodeinteractive.com/bridge/ , if you actually go here: http://demo.qodeinteractive.com/bridge/portfolio/gallery-style-condensed/two-columns-grid/ , you can see that, once looking at dev tools, that they apply a margin of "1px" on left/right side

    .projects_holder.hover_text.no_space article .image img {
       margin: 0 1px;
    }
    

    If you disable that style, you'll see the image move as you're describing when hovering on the image.

    Therefore, your CSS for the image should be:

    figure img {
       width: 100%;
       transform: scale(1);
       transition: transform 0.3s ease-in-out;
       display: block;  /* (or inline-block) */
       margin: 0 1px;
    }
    
    0 讨论(0)
  • 2021-02-20 05:12

    I just run over the same issue and for me it looks like that the browser corrects the decimal pixel after the scaling is done. Or some how the height and the width doesn't get scaled equals and that gets corrected in the end.

    So I think the solution is to use an image with a 1 x 1 ration factor.

    So for me the code of the question works fine when I use a the lorempixel with a width and height of 400px.

    Let me know if that solves the issue?!

    figure {
       display: block;
       overflow: hidden;
       position: relative;
       backface-visibility: hidden;
    }
    figure img {
       width: 100%;
       transform: scale(1);
       transition: transform 0.3s ease-in-out;
       }
    figure:hover img {
       transform: scale(1.1);
    }
     <figure>
         <img class="img-responsive" src="http://lorempixel.com/400/400/fashion/7">
     </figure>

    0 讨论(0)
  • 2021-02-20 05:18

    I have just run into this same problem now. The solutions here didn't fix the issue, so I'm posting what I did to get this to work.

    Like OP I had a container with oveflow hidden and was the same size as the image inside it. The image would scale on hover to create a 'zoom' effect - but when initially starting and ending the transition, the image was "jumping"/growing a tiny bit on the bottom and right-hand side. This made it jumpy and not smooth.

    I had calculated the dimensions of my components based off of percentages, which caused them to be non-integers (Chrome). I have a feeling Scale & Scale3d round the pixel values when scaling, which caused this jump. I gave a parent container display:table, which caused all children to have their width/heights be rounded to be an integer value. This fixed the issue for me, and the images now scale smoothly!

    0 讨论(0)
  • 2021-02-20 05:20

    I had a similar problem on my project. All images were position: absolute; and the transform look like that:

    figure img{
       transform: translate( -50%, 50%) scale(1);
       position: absolute;
       top: 50%;
       left: 50%;
    }
    
    figure img:hover{
       transform: translate( -50%, 50%) scale(1.1);
    }
    

    I replace every scale with scale3d and that solved my problem. The final styles look like that:

    figure img{
       transform: translate( -50%, 50%) scale3d(1, 1, 1);
       position: absolute;
       top: 50%;
       left: 50%;
    }
    
    figure img:hover{
       transform: translate( -50%, 50%) scale3d(1.1, 1.1, 1);
    }
    

    Hope that's will fix your problem

    0 讨论(0)
提交回复
热议问题