美文网首页
CSS3实现优酷轮播图

CSS3实现优酷轮播图

作者: 刘翾 | 来源:发表于2017-11-08 21:25 被阅读86次

CSS3实在是强大, 复杂的动画由CSS来实现着实让人好理解, 闲话不多说直接进入正题。今天实验的不是沉浸式轮播图, 而是类似优酷的立体轮播图


一· 效果演示

这里写图片描述

二· 页面布局

页面布局同正常的轮播图一样没什么好说的。上代码.

<!-- width:500px height:300px -->//我选的图片正常尺寸
    <div class="wrapper">
        <div class="move">
            <img src="1.jpg">
        </div>
        <div class="move">
            <img src="2.jpg">
        </div>
        <div class="move">
            <img src="3.jpg">
        </div>
        <div class="move">
            <img src="4.jpg">
        </div>
        <div class="move">
            <img src="5.jpg">
        </div>
    </div>

三· 思想说明

这里写图片描述

注意到图片到两边时height应该为0, 但是为了视觉效果图片上还是给了一些高度。
总共轮播一共5种状态, 因此一个animation属性要设置0%, 20%, 40%, 60%, 80%, 100%, 这五种状态。 但是由于开始时盒子内已经有三张起始图片因此我认为应该要写4种运动动画, 3个是开始的图片三个, 第4个动画是通用的。每一次的运动就是分别改变left, height, width, 等几种属性。

 @keyframes start1 {
            0% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            20% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            40% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            60% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            80% {

                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            100% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
        }
        @keyframes start2 {
            0% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            20% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            40% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            60% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            80% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            100% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
        }
        @keyframes start3 {
            0% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            20% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            40% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            60% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            80% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            100% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
        }
        @keyframes start4 {
            0% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            20% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            40% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            60% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            80% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            100% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
        }

四· 总代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优酷轮播图</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        img{
            border:0;
        }
        ol, ul ,li{list-style: none;}
        /* 盒子样式 */
        .wrapper {
            position: relative;
            width: 800px;
            /*500 + 200 + 200*/
            height: 300px;
            margin:  0 auto;
            overflow: hidden;
        }
        .wrapper .move {
            position: absolute;
            top: 50%;
            width: 200px;
            float: left;
            opacity: 0.4;
            left: 900px;
            z-index: 1;
            height:0px;
            margin-top:0px;
        }
        .wrapper .move img {
            width: 100%;
            height: 100%;
        }
        .wrapper .move:nth-child(1) {
            animation: start1 5s ease-in-out infinite;
        }
        .wrapper .move:nth-child(2) {
            animation: start2 5s ease-in-out infinite;
        }
        .wrapper .move:nth-child(3) {
            animation: start3 5s ease-in-out infinite;
        }
        .wrapper .move:nth-child(4) {
            animation: start4 5s ease-in-out  infinite;
        }
        .wrapper .move:nth-child(5) {
            animation: start4 5s ease-in-out 1s infinite;
        }
        @keyframes start1 {
            0% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            20% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            40% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            60% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            80% {

                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            100% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
        }
        @keyframes start2 {
            0% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            20% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            40% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            60% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            80% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            100% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
        }
        @keyframes start3 {
            0% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            20% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            40% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            60% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            80% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            100% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
        }
        @keyframes start4 {
            0% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            20% {
                top: 50%;
                margin-top: -60px;
                height: 120px;
                width: 200px;
                left: 650px;
                opacity: 0.3;
                z-index: 1;
            }
            40% {
                top:0;
                margin-top:0;
                height:300px;
                width:500px;
                left:150px;
                opacity:1;
                z-index:100;
            }
            60% {
                top:50%;
                margin-top:-60px;
                height:120px;
                width:200px;
                left:0px;
                opacity:0.3;
                z-index:1;
            }
            80% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: -200px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
            100% {
                top: 50%;
                width: 200px;
                opacity: 0.4;
                left: 900px;
                z-index: 1;
                height:0px;
                margin-top:0px;
            }
        }
    </style>
</head>
<body>
    <!-- width:500px height:300px -->
    <div class="wrapper">
        <div class="move">
            <img src="1.jpg">
        </div>
        <div class="move">
            <img src="2.jpg">
        </div>
        <div class="move">
            <img src="3.jpg">
        </div>
        <div class="move">
            <img src="4.jpg">
        </div>
        <div class="move">
            <img src="5.jpg">
        </div>
    </div>
</body>
</html>

相关文章

  • CSS3实现优酷轮播图

    CSS3实在是强大, 复杂的动画由CSS来实现着实让人好理解, 闲话不多说直接进入正题。今天实验的不是沉浸式轮播图...

  • 技术练习的demo集

    demo1 实现优酷轮播图效果 页面效果展示 功能:自动轮播,hover停止轮播,点击left/right上一页/...

  • 2019-10-30 自定义轮播图

    构思: 轮播图-生活-高清完整正版视频在线观看-优酷 明确目标: 根据录制的视频,先明确轮播图的实际效果,视频中图...

  • 纯css3:radio+label实现轮播图

    预览地址:纯css3:radio+label实现轮播图 轮播图这东西,我相信只要是做前端的,肯定都做过,不过大部分...

  • 用四种方法实现轮播图

    1、css3动画实现的轮播图 实现原理如下呀: 1、设置大的div a)设置绝对定位,定位位置,b)设置图片展示...

  • 轮播图心得

    轮播图 写轮播图之前我们要认识到几个问题:一、什么是轮播图?二、怎么实现轮播效果?三、轮播图还有什么小功能可以实现...

  • 轮播图实现

    轮播图在实际应用开发使用较多,本文说明一下具体的实现过程。 一、实现轮播图的基本控件介绍。实现轮播图需要将多张图片...

  • swift UICollectionView 实现无限轮播图

    无线轮播图的实现方式有很多,这里介绍如何通过 UICollectionView 实现无线轮播图.效果图如下: 具体...

  • swift轮播图的实现-UIScrollView

    目标 :UIScrollView+三UIImageView的轮播图实现 原理:利用UIScrollView实现轮播...

  • 项目-轮播图

    整个轮播图分为三部分:轮播指标、轮播项目及轮播导航。用boostrap实现轮播图要比用js、jQuery方便的多,...

网友评论

      本文标题:CSS3实现优酷轮播图

      本文链接:https://www.haomeiwen.com/subject/recumxtx.html