zoukankan      html  css  js  c++  java
  • layui(八)——轮播图常见用法总结

      carousel 是 layui 2.0 版本中新增的全新模块,主要适用于跑马灯/轮播等交互场景。它可以满足任何类型内容的轮播式切换操作,更可以胜任 FullPage (全屏上下轮播)的需求,简洁而不失强劲,灵活而优雅。

    常见的options和方法整理如下:

        <div class="layui-carousel" id="test1" lay-filter="carofilter" style="font-size:larger">
            <div carousel-item>
                <div style="background-color:red">条目1</div>
                <div style="background-color:green">条目2</div>
                <div style="background-color:blue">条目3</div>
                <div style="background-color:mediumorchid">条目4</div>
                <div style="background-color:orange">条目5</div>
            </div>
        </div>
        <!-- 条目中可以是任意内容,如:<img src=""> -->
        <script>
            layui.use('carousel', function () {
                var carousel = layui.carousel;
                //***************************建造实例
                var ins=carousel.render({
                    elem: '#test1'
                    ,  '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

  • 相关阅读:
    Swift
    Swift
    第二章_session管理
    HDU-1387-Team Queue
    Install Orace 11g on Solaris 10 Sparc 64 bit
    Linux 多学习过程
    dispatch_once认识分析
    关于包围神经猫的想法实现
    嵌入在网站上Flash播放机(2)
    初学者应学会如何加快seo
  • 原文地址:https://www.cnblogs.com/wyy1234/p/9455848.html
Copyright © 2011-2022 走看看