H5移动端手势滑动圆盘转动效果

这里写图片描述

<!doctype html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="viewport" content="user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv = "Cache-Control" content = "no-transform">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <meta name = "applicable-device" content = "mobile">
    <title>jquery.rotate旋转插件</title>
    <style>
        #box{height:800px;width:800px;margin:100px auto;line-height:900px;text-align:Center;color:#fff;font-size:120px;background:red;transition: all 1s;border-radius:400px;}
        #box .out-circle{position:relative;top:150px;width:500px;height:500px;border-radius:300px;margin:0 auto;background:yellow;}
        #box .item{position:absolute;left:175px;top:175px;width:150px;height:150px;border-radius:75px;line-height:150px;}

        #box .out-circle div:nth-of-type(2){transform: rotate(60deg);}
        #box .out-circle div:nth-of-type(3){transform: rotate(120deg);}
        #box .out-circle div:nth-of-type(4){transform: rotate(180deg);}
        #box .out-circle div:nth-of-type(5){transform: rotate(240deg);}
        #box .out-circle div:nth-of-type(6){transform: rotate(300deg);}
        #box .out-circle div:nth-of-type(1) a{border-radius:75px;background:blue;display:block;height:150px;width:150px;transform:translateX(-325px);}
        #box .out-circle div:nth-of-type(2) a{border-radius:75px;background:pink;display:block;height:150px;width:150px;transform: translateX(-325px);}
        #box .out-circle div:nth-of-type(3) a{border-radius:75px;background:black;display:block;height:150px;width:150px;transform: translateX(-325px);}
        #box .out-circle div:nth-of-type(4) a{border-radius:75px;background:green;display:block;height:150px;width:150px;transform: translateX(-325px);}
        #box .out-circle div:nth-of-type(5) a{border-radius:75px;background:orangered;display:block;height:150px;width:150px;transform: translateX(-325px);}
        #box .out-circle div:nth-of-type(6) a{border-radius:75px;background:olivedrab;display:block;height:150px;width:150px;transform: translateX(-325px);}
    </style>
</head>

<body>
    <div id="box" style="transform:rotate(0deg)">
        <div class="out-circle">
            <div class="item">
                <a href="#">1</a>
            </div>
            <div class="item">
                <a href="#">2</a>
            </div>
            <div class="item">
                <a href="#">3</a>
            </div>
            <div class="item">
                <a href="#">4</a>
            </div>
            <div class="item">
                <a href="#">5</a>
            </div>
            <div class="item">
                <a href="#">6</a>
            </div>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">


    var deg = 0;
    var startX = 0;
    var endX = 0;
    var box = document.querySelector("#box");

    function boxTouchStart(e) {
        var touch = e.touches[0]; //获取触摸对象
        startX = touch.clientX; //获取触摸坐标
        console.log(touch);
    }

    function boxTouchMove(e) {

        endX = e.touches[0].clientX; //获取触摸坐标

    }

    function boxTouchEnd(e) {

        console.log(endX +"end");
        console.log(startX +"start");
        deg = parseInt(box.style.webkitTransform.replace("rotate(", ""));

        //向右边滑动
        if(endX - startX > 0){
            //console.log(deg);
            deg = deg + 90;
            box.style.webkitTransform = "rotate(" + deg + "deg)";
        }else{
            deg = deg - 90;
            console.log(deg);
            box.style.webkitTransform = "rotate(" + deg + "deg)";
        }
    }

    box.addEventListener("touchstart", boxTouchStart, false);
    box.addEventListener("touchmove", boxTouchMove, false);
    box.addEventListener("touchend", boxTouchEnd, false);



</script>


  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值