html5+css如何实现中间大两头小的轮播效果


Posted in HTML / CSS onDecember 06, 2018

国际惯例,先上效果

html5+css如何实现中间大两头小的轮播效果

好了,话不多说,上去就是一顿撸。

css:

<style>

   *{margin: 0;padding: 0}
   .wrap{
       
   }
   .container{
       width: 100%;
       overflow: hidden;
       /* height: 400px; */
       background: red;
       position: relative;
   }
   .box{width: 125%;
       height: auto;
       display: flex;
        align-items: center;
        position: relative;
        left: 0;
       }
    .box li{
        width: 20%;
        float: left;
        list-style: none;
        -webkit-transition: width 0.5s, height 0.5s, margin 0.5s;
        position: relative;
    }
    .box video {
        width: 100%;
        height: 100%;
    }
    .box li div {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }
    .box li div img {
        width: 100%;
        height: 100%;
    }
    /* .box li:nth-child(2){
        height: 360px;
        margin: 0 1%;
    } */
    .goLeft, .goRight {
        position: absolute;
        width: 28px;
        height: 52px;
        top: 50%;
        transform: translate(0,-50%);
        cursor: pointer;
        border: none;
        outline: none;
        line-height: 52px;
    }
    .goLeft {
        left: 20%;
    }
    .goRight {
        right: 20%;
    }
    .box li>p {
        margin: 0;
        color: #fff;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        text-align: center;
    }
    .box li>p>span {
        display: inline-block;
        width: 100px;
        height: 100px;
        background: url(play.png);
    }
    .ddd{
        width: 100%;
        height: 360px;
        display: flex;
align-items: center;
position: relative;
    }
    .dd-2{
        width: 20%;
        background: yellow;
    }
    .aa{
        width: 100%;
    }
</style>

html:

<div class="wrap">

    <div class="container">
        <ul class="box">
            <li class="video1">
                <video></video>
                <div><img src="3.jpg" alt="">1</div>
            </li>
            <li class="video2">
                <video></video>
                <div><img src="3.jpg" alt="">2</div>
            </li>
            <li class="video3">
                <video></video>
                <div><img src="3.jpg" alt="">3</div>
            </li>
            <li class="video4">
                <video></video>
                <div><img src="3.jpg" alt="">4</div>
            </li>
        </ul>
        <button onclick="moveRight()" class="goLeft btn">左</button> 
        <button onclick="moveLeft()" class="goRight btn">右</button>
    </div>
    <div class="ddd">
        <div class="dd-2"><div class="aa">aaa</div><div class="bb">vvvv</div></div>
    </div>
</div>

js:

$(function(){
    $('.box>li:nth(1)').css({ width: '36%', margin: '0 2%' })
    $('.box>li:nth(1)').append('视频主题')
    
})
$(window).resize(function () {          //当浏览器大小变化时
    $('.box').css('height', 'auto')
})
function moveLeft(){
        var height = $('.box>li:nth(1)').height()
        $('.box').css('height', height)
        $('.box>li').css({ width: '20%', margin: '0 0%' })
        $('.box>li:nth(2)').css({ width: '36%', margin: '0 2%' })
        $('.box').animate({
            left: '-25%'
        }, 400, function () {
            // 把第一个子元素移到最后,并且设置left=0
            $(".box").append($('.box>li:nth(0)')[0]);
            $(".dd-2").append($('.aa')[0]);
            $(".aa").append('ccc');
            $('.box').css('left', 0);
            $(".btn").attr("disabled", false);
            $('.box>li:nth(1)').append('视频主题')

        });
    }
    function moveRight(){
        $('.box>li').css({ width: '20%', margin: '0 0%' })
        $('.box>li:nth(0)').css({ width: '36%', margin: '0 2%' })
        var height = $('.box>li:nth(1)').height()
        $('.box').css('height', height)
        $(".box").prepend($('.box>li:nth(3)')[0]);
        
        $('.box').css('left', '-20%');
        $('.box').animate({
            left: 0
        }, 400, function () {
            $(".btn").attr("disabled", false);
            $('.box>li:nth(1)').append('视频主题')
        });
    }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

HTML / CSS 相关文章推荐
button在IE6/7下的黑边去除方案
Dec 24 HTML / CSS
利用CSS3的border-radius绘制太极及爱心图案示例
May 17 HTML / CSS
HTML5实现分享到微信好友朋友圈QQ好友QQ空间微博二维码功能
Jan 03 HTML / CSS
HTML5之SVG 2D入门5—颜色的表示及定义方式
Jan 30 HTML / CSS
html5配合css3实现带提示文字的输入框(摆脱js)
Mar 08 HTML / CSS
简单html5代码获取地理位置
Mar 31 HTML / CSS
HTML5几个设计和修改的页面范例分享
Sep 29 HTML / CSS
html5 canvas的绘制文本自动换行的示例代码
Sep 17 HTML / CSS
amazeui 验证按钮扩展的实现
Aug 21 HTML / CSS
CSS3 实现NES游戏机的示例代码
Apr 21 HTML / CSS
CSS预处理框架——Stylus
Apr 21 HTML / CSS
浅谈由position属性引申的css进阶讨论
May 25 HTML / CSS
Html5 Canvas动画基础碰撞检测的实现
Dec 06 #HTML / CSS
canvas压缩图片以及卡片制作的方法示例
Dec 04 #HTML / CSS
canvas探照灯效果的示例代码
Nov 30 #HTML / CSS
localStorage的过期时间设置的方法详解
Nov 26 #HTML / CSS
canvas拼图功能实现代码示例
Nov 21 #HTML / CSS
详解Canvas 跨域脱坑实践
Nov 07 #HTML / CSS
浅谈移动端网页图片预加载方案
Nov 05 #HTML / CSS
You might like
php intval的测试代码发现问题
2008/07/27 PHP
PHP在字符断点处截断文字的实现代码
2011/04/21 PHP
实用PHP会员权限控制实现原理分析
2011/05/29 PHP
php获取文件大小的方法
2014/02/26 PHP
yii实现model添加默认值的方法(2种方法)
2016/01/06 PHP
php封装的page分页类完整实例
2016/10/18 PHP
PHP递归的三种常用方式
2019/02/28 PHP
laravel通过a标签从视图向控制器实现传值
2019/10/15 PHP
jquery中动态效果小结
2010/12/16 Javascript
深入JavaScript高级程序设计之对象、数组(栈方法,队列方法,重排序方法,迭代方法)
2015/12/01 Javascript
Jqgrid之强大的表格插件应用
2015/12/02 Javascript
JQUERY的AJAX请求缓存里的数据问题处理
2016/02/23 Javascript
Bootstrap实现登录校验表单(带验证码)
2016/06/23 Javascript
实例详解jQuery的无new构建
2016/08/02 Javascript
微信小程序 animation API详解及实例代码
2016/10/08 Javascript
Bootstrap中定制LESS-颜色及导航条(推荐)
2016/11/21 Javascript
JS绘制微信小程序画布时钟
2016/12/24 Javascript
bootstrap3中container与container_fluid外层容器的区别讲解
2017/12/04 Javascript
node+koa2+mysql+bootstrap搭建一个前端论坛
2018/05/06 Javascript
javascript面向对象程序设计实践常用知识点总结
2019/07/29 Javascript
python实现划词翻译
2020/04/23 Python
详解Python pygame安装过程笔记
2017/06/05 Python
python的变量与赋值详细分析
2017/11/08 Python
浅谈Python2、Python3相对路径、绝对路径导入方法
2018/06/22 Python
对python捕获ctrl+c手工中断程序的两种方法详解
2018/12/26 Python
Python创建字典的八种方式
2019/02/27 Python
python爬虫beautifulsoup库使用操作教程全解(python爬虫基础入门)
2021/02/19 Python
CSS3动画效果回调处理详解
2014/12/10 HTML / CSS
Html5移动端适配IphoneX等机型的方法
2019/06/25 HTML / CSS
物业经理求职自我评价
2013/09/22 职场文书
会计学毕业生求职信
2014/06/25 职场文书
驻村工作先进事迹
2014/08/14 职场文书
个人授权委托书范本
2014/09/14 职场文书
2015国庆66周年宣传语
2015/07/14 职场文书
4种非常实用的python内置数据结构
2021/04/28 Python
科学家测试在太空中培育人造肉,用于未来太空旅行
2022/04/29 数码科技