html - 使用 CSS 创建网页背景淡入淡出

标签 html css

我想制作一个网站,当您打开它时,背景会淡入不同的颜色。

示例:

/* Chrome, Safari, Opera */
@-webkit-keyframes {
    from {
        background: white;
    }

    to {
        background: #F7F2E0;
    }
}

/* Firefox */
@-moz-keyframes {
    from {
        background: white;
    }

    to {
        background: #F7F2E0;
    }
}

@keyframes {
    from {
        background: white;
    }

    to {
        background: #F7F2E0;
    }
}

但是当我运行脚本时,没有任何反应。

最佳答案

您需要为动画添加名称,然后将动画属性添加到所需的元素。

Example Here

@keyframes background {
    from {
        background:white;
    }
    to {
        background:#000;
    }
}

animation shorthand下面,为 animation-fill-mode 属性添加值 forwards 以便在最后一种颜色结束动画。

body {
    animation: background 4s forwards;
}

为简单起见省略了供应商前缀 - 请参阅 the example完整的 CSS。

我建议阅读更多关于 CSS animations at MDN 的内容.

关于html - 使用 CSS 创建网页背景淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23457984/

相关文章:

javascript - 如何在 jquery 中阻止这种限制单词的奇怪事情?

html - 3 张图片并排放置,每张图片上方有文字(每张 2 个词,以换行符分隔),整个内容居中

html - 如何在网站上显示电子邮件地址以避免垃圾邮件?

javascript - 如何更换€用javascript转换成欧元?

HTML li 显示为 table-cell 无法向右浮动

html - css3 -moz-border-image 不工作?

javascript - 放大 map 图像,其中包含可突出显示的部分

jquery - 如何使用 JQuery 滚动重复背景?

javascript - CSS 过渡只能在 FF 和 Chrome 中工作一次

javascript - JS一键切换(不是两次点击)-切换元素的默认值