效果图

22HUI - 轮播组件(hui-swipe)_# HUI

DOM 结构

<div style="padding:10px;">
    <div class="hui-swipe" id="swipe">
        <div class="hui-swipe-items">
           <div class="hui-swipe-item">轮播项目</div>
           <div class="hui-swipe-item">轮播项目</div>
        </div>
    </div>
</div>
请使用一个div包裹 .hui-swipe
huiSwpie对象使用说明

需要引用 hui-Swipe.js 并进行轮播插件初始化。操作步骤:

  1. 通过 new huiSwipe(’#轮播组件外层dom id’) 获得轮播对象;
  2. 执行轮播对象的 run()方法。
  3. 在run方法执行前可以通过轮播对象的属性来控制轮播的效果;
huiSwpie对象属性说明

loop 是否循环播放,默认 true;
speed 每帧动画切换时的动画时间,默认 500, 单位:毫秒;
delay 轮播间隔时间,默认 5000,单位:毫秒;
indicatorOn 是否展示进度点,默认 true;
autoPlay 是否自动播放,默认 true;

关于动态加载

获取动态图片信息后整合成

<div class="hui-swipe-item"><img src=""/></div>

追加到轮播组件内,然后再获取轮播对象,执行其run方法;

代码

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>HUI 轮播组件</title>
<link rel="stylesheet" type="text/css" href="../css/hui.css" />
</head>
<body>
<header class="hui-header">
    <div id="hui-back"></div>
    <h1>HUI 轮播组件</h1>
</header>
<div class="hui-wrap">
    <div class="hui-common-title" style="margin-top:15px;">
        <div class="hui-common-title-line"></div>
        <div class="hui-common-title-txt">轮播组件演示</div>
        <div class="hui-common-title-line"></div>
    </div>
    <div style="padding:10px;">
        <div class="hui-swipe" id="swipe">
            <div class="hui-swipe-items">
                <div class="hui-swipe-item"><img src="../img/swipe/1.jpg"/></div>
                <div class="hui-swipe-item"><img src="../img/swipe/2.jpg"/></div>
                <div class="hui-swipe-item"><img src="../img/swipe/3.jpg"/></div>
                <div class="hui-swipe-item"><img src="../img/swipe/4.jpg"/></div>
            </div>
        </div>
    </div>
    <div class="hui-common-title" style="margin-top:15px;">
        <div class="hui-common-title-line"></div>
        <div class="hui-common-title-txt">远程图片获取</div>
        <div class="hui-common-title-line"></div>
    </div>
    <div style="padding:10px; width:260px;">
        <div class="hui-swipe" id="swipe2">
            <div class="hui-swipe-items"></div>
        </div>
    </div>
</div>
<script src="../js/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/hui-swipe.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var swipe = new huiSwpie('#swipe');
swipe.autoPlay = false;
swipe.run();
//加载远程图片示例
hui.get(
    'http://hoa.hcoder.net/index.php?user=hcoder&pwd=hcoder&m=lunbo',
    function(res){
        var arr  = res.split('--hcSplitor--');
        for(var i = 0; i < arr.length; i++){
            var div = document.createElement('div')
            div.setAttribute('class', 'hui-swipe-item');
            div.innerHTML = arr[i];
            hui(div).appendTo('#swipe2 .hui-swipe-items');
        }
        var swipe2 = new huiSwpie('#swipe2');
        swipe2.run();
    },
    function(){
        hui.toast('读取远程数据失败');
    }
);
</script>
</body>
</html>