其他分享
首页 > 其他分享> > HTML+CSS+JS实现 ❤️夜晚云层动画特效❤️

HTML+CSS+JS实现 ❤️夜晚云层动画特效❤️

作者:互联网

   效果演示:

基于css3 keyframes 属性制作乌云密布云层动画,夜晚云层飘过动画特效。可用于网页动态云层背景特效。利用animation 和png云图片制作完成。 

   代码目录:

 

主要代码实现:

css样式:

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background: #000;
    text-align: center;

@keyframes clouds-loop-1 {
    to {
        background-position: -1000px 0;
    }
}

.clouds-1 {
    background-image: url("../img/clouds_2.webp");
    animation: clouds-loop-1 20s infinite linear;
}

@keyframes clouds-loop-2 {
    to {
        background-position: -1000px 0;
    }
}

.clouds-2 {
    background-image: url("../img/clouds_1.webp");
    animation: clouds-loop-2 15s infinite linear;
}

@keyframes clouds-loop-3 {
    to {
        background-position: -1579px 0;
    }
}

.clouds-3 {
    background-image: url("../img/clouds_3.webp");
    animation: clouds-loop-3 17s infinite linear;
}

html,
body {
    font-family: sans-serif;
    height: 100%;
    padding: 0;
    margin: 0;
}

body {
    background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuNSIgeTE9IjAuMCIgeDI9IjAuNSIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzMzMzMzMyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
    background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #333333), color-stop(100%, #000000));
    background: -moz-linear-gradient(#333333, #000000);
    background: -webkit-linear-gradient(#333333, #000000);
    background: linear-gradient(#333333, #000000);
}

body,
body a {
    color: #cccccc;
}

h1.quote {
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    display: inline-block;
    vertical-align: middle;
    *vertical-align: auto;
    *zoom: 1;
    *display: inline;
    text-align: right;
    text-decoration: none;
    font-family: 'Oswald', sans-serif;
    font-weight: normal;
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: 1.5em;
    line-height: 1.5em;
    margin: 0;
    text-shadow: 0 -1px 0 #ffffff, 0 2px 3px #000000;
}

h1.quote span {
    display: block;
}

.clouds {
    filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=40);
    opacity: 0.4;
    pointer-events: none;
    position: absolute;
    overflow: hidden;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
}

.clouds-1,
.clouds-2,
.clouds-3 {
    background-repeat: repeat-x;
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 500px;
}
}

body::before {
    content: "";
    display: inline-block;
    height: 100%;
    vertical-align: middle;
}

.scene {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    perspective: 15px;
    perspective-origin: 50% 50%;
}

.wrap {
    position: absolute;
    width: 1000px;
    height: 1000px;
    left: -500px;
    top: -500px;
    transform-style: preserve-3d;
    animation: move 12s infinite linear;
    animation-fill-mode: forwards;
}

.wrap:nth-child(2) {
    animation: move 12s infinite linear;
    animation-delay: 6s;
}

.wall {
    width: 100%;
    height: 100%;
    position: absolute;
    background: url(../img/sg.jpg);
    background-size: cover;
    opacity: 0;
    animation: fade 12s infinite linear;
}

.wrap:nth-child(2) .wall {
    animation-delay: 6s;
}

.wall-right {
    transform: rotateY(90deg) translateZ(500px);
}

.wall-left {
    transform: rotateY(-90deg) translateZ(500px);
}

.wall-top {
    transform: rotateX(90deg) translateZ(500px);
}

.wall-bottom {
    transform: rotateX(-90deg) translateZ(500px);
}

.wall-back {
    transform: rotateX(180deg) translateZ(500px);
}

@keyframes fade {
    0% {
        opacity: 0;
    }
    25% {
        opacity: 1;
    }
    75% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

@keyframes move {
    0% {
        transform: translateZ(-500px) rotate(0deg);
    }
    100% {
        transform: translateZ(500px) rotate(0deg);
    }
}

html代码 :

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>What do you have to be scared of?</title>

    <link rel="stylesheet" href="css/style.css">

    <script src="js/prefixfree.min.js"></script>

</head>

<body>

    <h1 class='quote'>
        <span>你是个鬼魂,驾驶着一具用星尘做成的肉骨架。</span>
        <span>... 你害怕什么?</span>
    </h1>



    <div class='clouds'>
        <div class='clouds-1'></div>
        <div class='clouds-2'></div>
        <div class='clouds-3'></div>
    </div>


</body>

</html>

需要把JS引入进来、图片也可以替换成自己喜欢的样子。

源码获取

精彩推荐更新中:

HTML5大作业实战100套

  打卡 文章 更新  36  /  100天

大家可以点赞、收藏、关注、评论我啦 、需要完整文件随时联系我或交流哟~!

在这里插入图片描述

标签:clouds,linear,100%,50%,transform,JS,HTML,background,CSS
来源: https://blog.csdn.net/weixin_39709134/article/details/120090014