Ionic2-Gestures tap press pan swipe等手势事件

205 篇文章 0 订阅
175 篇文章 1 订阅

原文出处:http://www.360doc.com/content/17/0407/16/16002580_643656532.shtml
先上效果:

基本的手势可以通过绑定到tap(点击),press(按下),pan(随着手指移动),swipe(随着手指迅速移动),rotate(旋转),pinch(缩放)等事件上的HTML元素来使用,这里只演示前四个。

html

<!-
Generated template for the Gestures page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on 
lonic pages and navigation.
--> 

<!--<ion-header>
<ion-navbar>
    <ion-title>Gestures</ion-title>
</ion-navbar>
</ion-header>-->

<ion-content padding>

  <ion-card (tap)="tapEvent($evnet)">
    <!-这是通过数据绑定的方式-->
    <ion-item>点击: {{tap}}次</ion-item>
  </ion-card>

  <ion-card (press)="pressEvent($event)">
    <!--这是通过数据绑定的方式-->
    <ion-item>按下: {{press}}次</ion-item>
  </ion-card>

   <ion-card (pan)="panEvent($event)">
      <!--这是通过数据绑定的方式-->
      <ion-item>手指滑动: {{pan}}次</ion-item>
    </ion-card>

    <ion-card (swipe)="swipeEvent($evnet)">
       <!--这是通过数据绑定的方式-->
       <ion-item>手指迅速滑动: {{swipe}}次</ion-item>
    </ion-card>
</ion-content>

ts

import ( Component } from '@angular/core';
import { NavController } from 'ionic-angular'; 

/*
Generated class for the Gestures page.
See http://ionicframework.com/docs/v2/components/#navigation for more info on 
lonic pages and navigation.
*/

@Component({
    selector: 'page-gestures',
    templateUrl: 'gestures.html'
})
export class GesturesPage {
    public tap: number =0;
    public press: number =0; 
    public pan: number =0;
    public swipe: number = 0;

  constructor(){ } 

  /**
  *点击事件处理
  */ 
  tapEvent(e) {
    // console.log(e);
    this.tap++;
  }

  /**
  *按下事件
  */
  pressEvent(e)
    //console.log(e);
    this.press++;
  }

  /*
  *滑动事件
  */
  panEvent(e) {
    // console.log(e);
    this.pan++;
  }

  /*
  *迅速滑动事件
  */
  swipeEvent(e) { 
    // console.log(e);
    this.swipe++; 
  }

  ionViewDidLoad(){
    console.log(Hello GesturesPage Page");
  }
}

 


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值