Grayscale image with CSS on Safari 5.x

后端 未结 4 1847

I am trying to show some images on a page where they should be shown in grayscale, except on mouse hover when they smoothly transition into color. I\'ve ma

4条回答
  •  星月不相逢
    2020-12-30 12:23

    This one worked great for me:


    img { float:left;
    filter: url("data:image/svg+xml;utf8,#grayscale"); /* Firefox 10+ */
        filter: gray; /* IE6-9 */
        -webkit-filter: grayscale(100%); /* Chrome 19+ & Safari 6+ */
        -webkit-backface-visibility: hidden; /* Fix for transition flickering */
        -webkit-transition: all 1.5s ease;
           -moz-transition: all 1.5s ease;
            -ms-transition: all 1.5s ease;
             -o-transition: all 1.5s ease;
                transition: all 1.5s ease;
                z-index: 40 !important;
                 display:block;
    
     }
    
    img:hover { 
      filter: url("data:image/svg+xml;utf8,#grayscale");
        -webkit-filter: grayscale(0%);}
    

    The images looks really overexposed in Safari however (But they are in greyscale). And the transition isn't supported by Firefox.

提交回复
热议问题