CSS animation动画实现轮播图

1、2d,3d无法实现动画的持续播放,所以采用animation来实现。

2、淡入淡出轮播图

结构层代码:
 <div class="box">
        <!-- 用来放轮播的图片 -->
        <div class="img">
            <ul class="item .clearfix">
                <li class="item-img item-img1"></li>
                <li class="item-img item-img2"></li>
                <li class="item-img item-img3"></li>
                <!-- <li class="item-img item-img4"></li>
            <li class="item-img item-img5"></li> -->
            </ul>
        </div>
        <!-- 用来放圆点 -->
        <div class="circle">
            <ul class="clearfix">
                <li>
                    <div class="focus focus1"></div>
                </li>
                <li>
                    <div class="focus focus2"></div>
                </li>
                <li>
                    <div class="focus focus3"></div>
                </li>
            </ul>
        </div>
    </div>
样式层代码:
*{
    margin: 0;
    padding:0;
}
.clearfix::after{
    content: '';
    display: block;
    clear: both;
}
.box{
    width: 100%;
    height: 400px;
    position: relative;
}
ul{
    list-style: none;/* 去除列表标记 */
}
.item{
    position: relative;
}
.item .item-img{
    width: 100%;
    height: 400px;
    position: absolute;
    background-size: cover;
    animation-name:fade;
    animation-duration:12s;/* 按照百分比来分配时间 */
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}
.item-img + .item-img{/* 当检测到指定盒子它的兄弟盒子会隐藏 */
    opacity: 0;
}
.item-img1{
    background: url(./choose-bg.jpg) no-repeat center center;
    animation-delay: -1s;/* 让第一张图马上播放 */
}
.item-img2{
    background: url(./info-bg.jpg) no-repeat center center;
    animation-delay: 3s;
}
.item-img3{
    background: url(./slider-bg.jpg) no-repeat center center;
    animation-delay: 7s;
}
/* .item-img4{
    background: url(./wedo-img2.jpg) no-repeat center center;
    animation-delay: 11s;
}
.item-img5{
    background: url(./wedo-img3.jpg) no-repeat center center;
    animation-delay: 15s;
} */

/* 4s完成一个生命周期
0-1s:淡入
1-4:持续显示
4s-最后:淡出,并且隐藏
以上过程适合每一个图片。
*/
/* 难点 */
@keyframes fade{
 /* 总共12s,完成关键帧。每一秒需要8.3% */
    0%{
       opacity: 0;
       z-index: 2; 
    }8.3%{
        /* 0-5 经历1s钟淡入 */
       opacity: 1;
       z-index: 2; 
    }33.2%{
        /* 0-20 3s持续显示 */
        opacity: 1;
        z-index: 2;
    }41.5%{
        opacity: 0;
        z-index: 0;
    }100%{
        opacity: 0;
        z-index: 0;
    }
}
.circle{
    position: absolute;
    top: 387px;
    width: 100px;
    height: 10px;
    z-index: 99;
    left: calc(50% - 100px);
}
.circle li{
    width: 10px;
    height: 10px;
    border: 1px white solid;
    border-radius: 100%;
    float: left;
    margin: 0 10px;
}
 .focus{
    width: 100%;
    height: 100%;
    background-color: gray;
    border-radius: 100%;
    animation: fade 12s linear;
}
.focus2,.focus3{
    opacity: 0;
}
.focus1{
    animation-delay: -1s;
}
.focus2{
    animation-delay: 3s;
}
.focus3{
    animation-delay: 7s;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

轻叹呀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值