ztouch练习2

<!DOCTYPE html>
<html>
<head lang="zh">
    <meta charset="UTF-8">
    <title></title>
<style>
    *{margin:0; padding: 0;}
    li{list-style-type: none;}


    .imgBox{
        width: 100%;
        overflow: hidden;
    }
    .imgInBox{
        width:400%;
    }
    .imgInBox li{
        float:left;
        width:25%;
        position: relative;
    }
    .imgInBox li img{
        width:100%;
    }
    .imgtitle{
        width:100%;
        background: rgba(0, 0, 0, 0.6);
        color: #fff;
        font-size: 16px;
        text-align: center;
        position: absolute;
        bottom: 0px;
        font-weight: 600;
        line-height: 16px;
        padding: 5px 0px;
    }
</style>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"/>


</head>
<body>
<div class="imgBox" id="imgBox">
       <ul class="imgInBox">
           <li><img src="./images/1.jpg">
           <div class="imgtitle">11111111111</div>
           </li>
           <li><img src="./images/2.jpg">
               <div class="imgtitle">22222222222</div></li>
           <li><img src="./images/3.jpg">
               <div class="imgtitle">33333333333333</div></li>
           <li><img src="./images/4.jpg">
               <div class="imgtitle">444444444</div></li>


       </ul>
</div>




<script type="text/javascript" src="js/libs/zepto/zepto.js"></script>
<script type="text/javascript" src="js/libs/zepto/zTouch.js"></script>
<script>
    var transformBox = function (obj,value,time,has3d) {
        var time=time?time:0;
        transl=has3d?"translate3d("+value+"px,0,0)":"translate("+value+"px,0)";
        obj.css({'-webkit-transform':transl,'-webkit-transition':time+'ms linear'});
    }
    
    




    //图片
    var autoSlide = function (tPoint) {
        var self = tPoint.self;
        var children = self.children();
        var width = children.width();
        //定时
        var imgInterval = setInterval(function () {
            var count = tPoint.count;
            if(count==-(tPoint.total-1)){
                count=0;
            }else{
                count--;
            }
            var offset = count*width/tPoint.total;
            transformBox(children,offset,500,tPoint.has3d);
            tPoint.setAttr("count",count);


        },2000);
        tPoint.setAttr("imgInterval",imgInterval);
    }
    var imgArgs = {
        sCallback: function (tPoint) {
            if(tPoint.imgInterval !=null){
                clearInterval(tPoint.imgInterval);
            }
        },
        mCallback: function (tPoint) {
            var self = tPoint.self;
            var children = self.children();
            var width = children.width();
            var offset = tPoint.mX+tPoint.count*width/tPoint.total;
            transformBox(children,offset,500,tPoint.has3d);
        },
        eCallback: function (tPoint){
            var self = tPoint.self;
            var children = self.children();
            var width = children.width();
            var count = tPoint.count;
            switch(tPoint.direction){
                case "left":
                    count--;
                    break;
                case "right":
                    count++;
                    break;
            }
            if(count==1 || count==-tPoint.total){
                count = tPoint.count;
            }
            var offset = count*width/tPoint.total;
            transformBox(children,offset,500,tPoint.has3d);
            tPoint.setAttr("count",count);
            autoSlide(tPoint);


        },
        afterCallback: function (tPoint) {
            autoSlide(tPoint);
        }
    }


    $("#imgBox").Swipe(imgArgs);
    
</script>
</body>

</html>


图片自动轮换,手动移动轮换


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值