swipe

触屏上当快速划过某个元素时触发

定义

触屏上当快速划过某个元素时触发

包括格外下面的属性:

swipe.distance

{Number} 划过的距离,单位 px

swipe.direction

{String} 划动方向,枚举: left right up down

swipe.duration

{Number} 滑动持续时间,单位秒

示例

<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-touch-fullscreen" content="yes">
    <script src="//g.alicdn.com/kissy/k/1.4.7/seed.js" data-config="{combine:true}"></script>
</head>
<body>

<h1>open in ios safari/chrome mobile to test swipe event</h1>

<div id='t' tabindex='0'
     style='border:1px solid green;
     width:200px;height:200px;margin:10px'>
    swipe me
</div>

<div style="height: 1080px"></div>
<script>
    KISSY.use('event', function (S, Event) {
        Event.on('#t', "swipe", function (e) {
            S.log(e.type + ' : fired');
            S.log(e.direction);
            S.log(e.distance);
            S.log(e.duration);
        });
        // for chrome
        Event.on('#t', "swiping", function (e) {
            if(e.direction=='left'){
                e.preventDefault();
            }
            if(e.direction=='right'){
                e.preventDefault();
            }
            // if need to prevent default y scroll
            if(e.direction=='up'){
                e.preventDefault();
            }
            if(e.direction=='down'){
                e.preventDefault();
            }
        });
    });
</script>
</body>
</html>