首页 > 移动平台 > 详细

移动端滑屏事件

时间:2018-01-19 23:05:30      阅读:209      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app" :class="{‘box‘:isActive}" @touchstart="slideStart" @touchend="slideEnd">
    {{ message }}
</div>
<script>
    var app = new Vue({
        el: ‘#app‘,
        data: {
            message: ‘Hello Vue!‘,
            isActive: true
        },
        methods: {
            slideStart: function (e) {
                this.startX = e.changedTouches[0].pageX;
                this.startY = e.changedTouches[0].pageY;
            },

            slideEnd: function (e) {
                this.endX = e.changedTouches[0].pageX;
                this.endY = e.changedTouches[0].pageY;
                this.moveX = this.endX-this.startX;
                this.moveY = this.endY-this.startY;

                if (this.moveX > 50) {
                    console.log(‘右‘);
                } else if (this.moveX < -50) {
                    console.log(‘左‘);
                }else if (this.moveY > 100) {
                    console.log(‘下‘);
                }else if (this.moveY < -100) {
                    console.log(‘上‘);
                }

                console.log(‘X:‘,this.moveX);
                console.log(‘Y:‘,this.moveY);
            }
        }
    })
</script>
<style>
    .box {
        width: 800px;
        height: 400px;
        background-color: gray;
    }
</style>
</body>
</html>

  

移动端滑屏事件

原文:https://www.cnblogs.com/huangtonghui/p/8318956.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!