gpt4 book ai didi

css - 淡入不适用于 IE

转载 作者:行者123 更新时间:2023-11-28 08:53:43 29 4
gpt4 key购买 nike

我正在使用此代码在页面加载时淡入图像。在我测试过的所有浏览器中工作正常,除了 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;}

有什么想法吗?

最佳答案

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

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

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

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

方法一:

如果您正在寻找自调用转换,那么您应该使用 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

关于css - 淡入不适用于 IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27239598/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com