【问题标题】:Fade In doesn't work on IE淡入在 IE 上不起作用
【发布时间】:2014-12-02 08:05:03
【问题描述】:

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

@-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;}

有什么想法吗?

【问题讨论】:

  • 是否适用于所有版本的 IE?什么版本?
  • 不支持过渡和动画until IE 10

标签: css internet-explorer


【解决方案1】:

您正在使用this 方法,它对 IE 有警告:

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

因为 IE9 不支持 css3 动画但支持 opacity: 0; 属性你必须让ie9加载一个单独的ie9 css 将所有淡入淡出类设置为不透明度:1

如果您正在寻找替代方案:

方法一:

如果您正在寻找自调用转换,那么您应该使用 CSS3 Animations,它们也不被支持,但这正是它们的用途。

CSS

#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; }
}

演示

浏览器支持

所有现代浏览器,IE 10+:http://caniuse.com/#feat=css-animation


方法二:

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

jQuery

$("#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";

演示

浏览器支持

所有现代浏览器,IE 10+:http://caniuse.com/#feat=css-transitions


方法三:

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

jQuery

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

CSS

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

演示

浏览器支持

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

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

Source

【讨论】:

  • 我正在尝试方法 3,但它对我不起作用。我的 HTML 是:
    ..
  • 谢谢,这行得通。但要记住的是不要将它放在媒体查询中;媒体查询中的动画在 IE 中不起作用。
【解决方案2】:

尝试添加前缀-ms-,例如-ms-animation-delay
因为您刚刚为mozilla 指定前缀-moz-,为chrome 指定前缀-webkit-

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多