CSS动画实现星星闪烁效果

在这里插入图片描述
一闪一闪亮晶晶,用来做背景很棒哦~

html部分

<div class="container">
       <div class="star star1"></div>
       <div class="star star2"></div>
       <div class="star star3"></div>
   </div> 

CSS部分

body { overflow: hidden; }
.container {
    position   : relative;
    top        : 0;
    left       : 50%;
    transform: translateX(-50%);
    width      : 1920px;
    height     : 600px;
    background : url(images/bg1.jpg) repeat
}

.star {
    position : absolute;
    top      : 0;
    left     : 50%;
    transform: translateX(-50%);
    width    : 1920px;
    height   : 500px;
    animation: star 2.5s ease-in infinite;
}

.star1 {
    background: url(images/bg_star_1.png) no-repeat center center;

}

.star2 {
    background: url(images/bg_star_2.png) no-repeat center center; animation-delay: .8s;
}

.star3 {
    background: url(images/bg_star_3.png) no-repeat center center; animation-delay: 1.7s;
}

@keyframes star {
    10% {
        opacity: 0;
    }

    90% {
        opacity: 1;
    }
}

animation是个宝藏

发布了21 篇原创文章 · 获赞 0 · 访问量 605

猜你喜欢

转载自blog.csdn.net/immocha/article/details/103528593