div 上的 CSS 不透明度随着时间延迟而不是用户交互而变化

2024-01-19

我正在尝试在 div 中设置一个图像,该图像将在 5 秒内缓慢出现(不透明度从 0 到 1)。我有这个代码:

.fadeDivIn {
opacity: 1;
transition: opacity 5s ease-in;
-moz-transition: opacity 5s ease-in;
-webkit-transition: opacity 5s ease-in;
-o-transition: opacity 5s ease-in;
}

但我不知道如何自动触发它。

我一直在使用 CSS3 关键帧进行向其他元素的过渡,并且理想地希望应用类似于不透明度的东西,但遇到了障碍。有人可以帮忙吗?


看看下面的例子,你需要使用关键帧

div {
    background: #333;
    width: 200px;
    height: 200px;
    -webkit-animation: smooth 5s ease-in;
    -moz-animation: smooth 5s ease-in;
    -o-animation: smooth 5s ease-in;
    -ms-animation: smooth 5s ease-in;
    animation: smooth 5s ease-in;
}

@-webkit-keyframes smooth {
    0% { opacity: 0;}
    100% { opacity: 1;}
}

一个例子 :http://jsfiddle.net/zxx8u/1/ http://jsfiddle.net/zxx8u/1/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

div 上的 CSS 不透明度随着时间延迟而不是用户交互而变化 的相关文章