手机端滑动、长按事件插件touchswipe.js的使用示例

请在这里查看示例 ☞ touchSwipe示例

<!DOCTYPE html>  
<html lang="en">  
<head>  
  <meta charset="UTF-8">  
  <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1">  
  <title>demo</title>  
  
  <script src="../js/jquery-1.11.3.min.js"></script>  
  <script src="js/jquery.touchSwipe.min.js"></script>  
  
  <style>  
    * {margin: 0; padding: 0;}  
    body,html {width: 100%; height: 100%; background: pink;}  
    .div1 {height: 200px; background: red;}  
    .div2 {height: 200px; background: blue;}  
  </style>  
</head>  
<body>  
    <p>改 demo 待完善...</p>
    <p>建议在手机端测试</p>
    <p class="disable">禁用</p>  
    <p class="enable">恢复</p>  
    <p class="destroy">销毁</p>  
    <p class="init">初始化</p>  
  
    <div class="div1">  
        滑动这里  
    </div>  
    <div class="div2">  
          
    </div>  
  
  
<script>  
    $(function() {  
        //兼容ie8+、手机端  
        $('.div1').swipe({  
            /*swipe: function(event, direction, distance, duration, fingerCount, fingerData) {  
                $('body').append('direction -> '+ direction);  
                $('body').append('distance -> '+ distance);  
                $('body').append('duration -> '+ duration);  
                $('body').append('fingerCount -> '+ fingerCount);  
  
            },*/  
  
            /*//向左滑  
            swipeLeft: function(event, direction, distance, duration, fingerCount, fingerData) {  
                $('body').append('direction -> '+ direction +'<br>');  
                $('body').append('distance -> '+ distance +'<br>');  
                $('body').append('duration -> '+ duration +'<br>');  
                $('body').append('fingerCount -> '+ fingerCount +'<br>');  
  
            },*/  
  
            /*//滑动过程中  
            swipeStatus:function(event, phase, direction, distance, duration, fingerCount, fingerData, currentDirection) {  
                var html = 'phase -> '+ phase +'<br>'+ 'direction -> '+ direction +'<br>'+'distance -> '+ distance +'<br>'+'duration -> '+ duration +'<br>'+'fingerCount -> '+ fingerCount +'<br>'+'currentDirection -> '+ currentDirection +'<br>';  
  
                $('.div2').html(html);  
            },  
            triggerOnTouchEnd: false,//启动超过阈值停止插件  
<p>            threshold: 200,//滑动阈值 distance > threshold 时 phase = end</p><p><span style="white-space:pre"> excludedElements: "button, input, select, textarea, .noSwipe",</span>//让a标签也支持滑动事件</p>allowPageScroll: 'auto',//滑动时不影响滚动条的正常滚动,该项只在swipeStatus生效            maxTimeThreshold: 5000,//触摸阈值 duration > maxTimeThreshold 时 phase = cancle  
            triggerOnTouchLeave: true,//手指离开对象,停止插件  
            fingers: 'all',//手指数量(手机端生效)*/  
            tap: function(event, target) {  
                $('.div2').append('<br>tap:'+ $(target).attr('class'));  
            },  
            doubleTap: function(event, target) {  
                $('.div2').append('<br>doubleTap:'+ $(target).attr('class'));  
            },  
            hold: function(event, target) {  
                $('.div2').append('<br>hold:'+ $(target).attr('class'));  
                  
            }  
        }).on('click', function(e) {//同时绑定click  
            $('.div2').append('<br>click:'+ $(this).attr('class'));  
        }).on('dblclick', function(e) {//同时绑定click  
            $('.div2').append('<br>dblclick:'+ $(this).attr('class'));  
        });  
  
        //  
        $('.disable').on('click', function() {  
            $('.div1').swipe('disable');  
        });  
        $('.enable').on('click', function() {  
            $('.div1').swipe('enable');  
        });  
        $('.destroy').on('click', function() {  
            $('.div1').swipe('destroy');  
        });  
        $('.init').on('click', function() {  
            $('.div1').swipe({  
                swipe: function() {  
                    console.log(1);  
                },  
            });  
        });  
  
  
    });  
  
  
      
</script>  
      
  
  
  
    
</body>  
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值