渐入在IE上不起作用 [英] Fade In doesn't work on IE

查看:89
本文介绍了渐入在IE上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码在页面加载时淡入图像.在我测试过的所有浏览器中都能正常工作,但Windows上的IE除外.

I am using this code to fade-in images when the page loads. Works fine in all browsers I have tested except from IE on Windows.

@-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.fade-in {opacity:0;-webkit-animation:fadeIn ease-in 1;-moz-animation:fadeIn ease-in 1;animation:fadeIn ease-in 1;-webkit-animation-fill-mode:forwards;-moz-animation-fill-mode:forwards;animation-fill-mode:forwards;-webkit-animation-duration:1.5s;-moz-animation-duration:1.5s;animation-duration:1.5s;}

.fade-in.one {-webkit-animation-delay: 0.3s;-moz-animation-delay: 0.3s;animation-delay: 0.3s;}
.fade-in.two {-webkit-animation-delay: 0.6s;-moz-animation-delay:0.6s;animation-delay: 0.6s;}
.fade-in.three {-webkit-animation-delay: 0.9s;-moz-animation-delay: 0.9s;animation-delay: 0.9s;}

有什么想法吗?

推荐答案

您正在使用

You are using this method and it has a warning for IE:

警告!此CSS3代码仅适用于Firefox,Chrome,Safari和 也许是IE的较新版本(版本9之后)

Warning! This CSS3 code will only work on Firefox, Chrome, Safari and maybe newer versions of IE (after version 9)

由于IE9不支持css3动画,但支持不透明度:0; 属性,您将不得不让ie9加载一个单独的ie9 css, 将所有淡入淡出类都设置为不透明:1

Since IE9 doesn’t support css3 animations but does support opacity: 0; property you will have to have ie9 load a separate ie9 css where you have all your fade classes set to opacity: 1

如果您正在寻找替代品:

If you are looking for alternative:

如果您正在寻找自动调用的过渡,则应使用 CSS3动画,它们也不被支持,但这恰恰是它们制作的目的.

If you are looking for a self-invoking transition then you should use CSS3 Animations, they aren't supported as well but this is exactly the kind of thing they were made for.

#test p {
    margin-top: 25px;
    font-size: 21px;
    text-align: center;

    -webkit-animation: fadein 2s; /* Safari, Chrome and Opera > 12.1 */
       -moz-animation: fadein 2s; /* Firefox < 16 */
        -ms-animation: fadein 2s; /* Internet Explorer */
         -o-animation: fadein 2s; /* Opera < 12.1 */
            animation: fadein 2s;
}

@keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Firefox < 16 */
@-moz-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Internet Explorer */
@-ms-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Opera < 12.1 */
@-o-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

演示

  • http://jsfiddle.net/SO_AMK/VV2ek/
  • Demo

    • http://jsfiddle.net/SO_AMK/VV2ek/
    • 所有现代浏览器,IE 10+: http://caniuse.com/#feat=css -动画

      All modern browsers, IE 10+: http://caniuse.com/#feat=css-animation


      或者,您可以使用jQuery(或普通JS,请参见第三个代码块)在加载时更改类:

      Alternatively, you can use jQuery (or plain JS, see third code block) to change the class on load:

      $("#test p").addClass("load");​
      

      CSS

      #test p {
          opacity: 0;
          font-size: 21px;
          margin-top: 25px;
          text-align: center;
      
          -webkit-transition: opacity 2s ease-in;
             -moz-transition: opacity 2s ease-in;
              -ms-transition: opacity 2s ease-in;
               -o-transition: opacity 2s ease-in;
                  transition: opacity 2s ease-in;
      }
      
      #test p.load {
          opacity: 1;
      }
      

      普通JS(不在演示中)

      document.getElementById("test").children[0].className += " load";
      

      演示

      • http://jsfiddle.net/SO_AMK/a9dnW/
      • Demo

        • http://jsfiddle.net/SO_AMK/a9dnW/
        • 所有现代浏览器,IE 10+: http://caniuse.com/#feat=css -过渡

          All modern browsers, IE 10+: http://caniuse.com/#feat=css-transitions


          或者,您可以使用 .Mail 使用的方法:

          Or, you can use the method that .Mail uses:

          $("#test p").delay(1000).animate({ opacity: 1 }, 700);​
          

          CSS

          #test p {
              opacity: 0;
              font-size: 21px;
              margin-top: 25px;
              text-align: center;
          }
          

          演示

          • http://jsfiddle.net/SO_AMK/a9dnW/3/
          • Demo

            • http://jsfiddle.net/SO_AMK/a9dnW/3/
            • jQuery 1.x :所有现代浏览器,IE 6+: http: //jquery.com/browser-support/
              jQuery 2.x :所有现代浏览器,IE 9+: http://jquery .com/browser-support/

              jQuery 1.x: All modern browsers, IE 6+: http://jquery.com/browser-support/
              jQuery 2.x: All modern browsers, IE 9+: http://jquery.com/browser-support/

              此方法是最兼容的方法,因为目标浏览器不需要支持CSS3过渡动画.

              This method is the most cross-compatible as the target browser does not need to support CSS3 transitions or animations.

              来源

              Source

              这篇关于渐入在IE上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆