CSS3 动画/淡入淡出

标签 css

下午好,我正在尝试在 3 秒后将一幅图像自动淡入另一幅图像。一旦第二张图片是 100% 不透明度,我需要它保留而不是循环。执行此操作的最佳方法是什么?

最佳答案

DEMO

CSS:

/*Add required verdon prefixes*/
img{   
    width:300px; height:300px;
    display:block;

    /* Background in place of `src` attribute*/
    background:url("http://placehold.it/200x200");

    opacity:0;

    /*`fade` = name; `3s` = duration; `1` - number of times animation takes place*/
    -webkit-animation:fade 3s 1;  
    -moz-animation:fade 3s 1;  

    -webkit-animation-fill-mode: forwards;  
    -moz-animation-fill-mode: forwards;  
}

@-webkit-keyframes fade{
    to{
        opacity:1;
        background:url("http://placehold.it/250x200");
    }
}

@-moz-keyframes fade{
    to{
        opacity:1;
        background:url("http://placehold.it/250x200");
    }
}

使用的重要属性:

animation-fill-mode - “animation-fill-mode CSS 属性指定 CSS 动画在执行前后应如何将样式应用于其目标。”
forwards 设置为一个值会使获取的最终属性保留在元素中。

关于CSS3 动画/淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23086910/

相关文章:

javascript - 使用 PHP 从完整图像路径获取图像名称

javascript - jquery 切换 id 而不是类?

javascript - CSS/JQUERY 使 div 可滚动而不显示滚动条

javascript - 输入字段中值更改时的 Css 更改。查询

ios - 允许在 iFrame 内缩放,但不允许在 iOS 页面上缩放

html - 以 Wordpress 为中心的导航

html - 如何在 html/css 有序列表中使用列表项的 block 子元素使元素编号具有自适应性?

html - 将 Bootstrap 粘性页脚与全高内容 DIV 相结合

javascript - div 标签不会换行文本

jquery - 如何在 Bootstrap 面板中实现可扩展内容