原文地址:https://www.cnblogs.com/wyy1234/p/9455848.html
carousel 是 layui 2.0 版本中新增的全新模块,主要适用于跑马灯/轮播等交互场景。它可以满足任何类型内容的轮播式切换操作,更可以胜任 FullPage (全屏上下轮播)的需求,简洁而不失强劲,灵活而优雅。
常见的options和方法整理如下:
<div class="layui-carousel" id="test1" lay-filter="carofilter" style="font-size:larger"> <div carousel-item> <div style=" padding: 0px; color: rgb(0, 0, 255); line-height: 1.5 !important;">>条目1</div> <div style=" padding: 0px; color: rgb(0, 0, 255); line-height: 1.5 !important;">>条目2</div> <div style=" padding: 0px; color: rgb(0, 0, 255); line-height: 1.5 !important;">>条目3</div> <div style=" padding: 0px; color: rgb(0, 0, 255); line-height: 1.5 !important;">>条目4</div> <div style=" padding: 0px; color: rgb(0, 0, 255); line-height: 1.5 !important;">>条目5</div> </div> </div> <!-- 条目中可以是任意内容,如:<img src=""> --> <script> layui.use('carousel', function () { var carousel = layui.carousel; //***************************建造实例 var ins=carousel.render({ elem: '#test1' , width: '500px' //设置容器宽度 , arrow: 'always' //始终显示箭头,可选hover,none //,anim: 'updown' //切换动画方式,可选fade,default , full: false //全屏 , autoplay: true //自动切换 , interval: 1000 //自动切换的时间间隔 , index: 3 //初始化时item索引,默认时0 , indicator:'inside' //指示器位置,可选outside,none }); //**************************监听轮播切换事件 carousel.on('change(carofilter)', function (obj) { //test1来源于对应HTML容器的 lay-filter="test1" 属性值 console.log(obj.index); //当前条目的索引 console.log(obj.prevIndex); //上一个条目的索引 console.log(obj.item); //当前条目的元素对象 }); //****************************重置轮播 //var ins = carousel.render(options); ins.reload({arrow:'hover'});//将arror从alway变成hover }); </script>
注:这是为了个人查找方便整理的文档,并没有总结完全,查看更多可访问官网http://www.layui.com/doc