Cross-browser way to flip html/image via Javascript/CSS?

前端 未结 4 532
走了就别回头了
走了就别回头了 2020-12-12 10:14

Is there a library/simple way to flip an image?

Flip image like this:

AABBCC      CCBBAA
AABBCC  ->  CCBBAA

I\'m not loo

4条回答
  •  [愿得一人]
    2020-12-12 10:27

    Just dug up this answer while trying to fix a bug, while the suggested answer is correct I have found that it breaks most modern CSS Linting rules regarding the inclusion of all vendor rules for the transform. However, including the -ms-tranform rule causes an odd bug in IE9 where it applies the filter and -ms-transform rules causing an image to flip and flip back again.

    Here is my suggested improvement which also supports CSS Lint rules:

    .flip-horizontal {
        -moz-transform: scaleX(-1);
        -webkit-transform: scaleX(-1);
        -o-transform: scaleX(-1);
        -ms-transform: scaleX(1); /* linting rule fix + IE9 fix */
        transform: scaleX(-1);
        -ms-filter: fliph;
        filter: fliph;
    }
    .flip-vertical {
        -moz-transform: scaleY(-1);
        -webkit-transform: scaleY(-1);
        -o-transform: scaleY(-1);
        -ms-transform: scaleY(1);  /* linting rule fix + IE9 fix */
        transform: scaleY(-1);
        -ms-filter: flipv;
        filter: flipv;
    }
    

提交回复
热议问题