欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

AngularJS ionic手勢(shì)事件的使用總結(jié)

 更新時(shí)間:2017年08月09日 10:19:37   作者:青_zq  
本篇文章主要介紹了AngularJS手勢(shì)事件的使用總結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

這兩天學(xué)習(xí)了AngularJS手勢(shì)事件感覺這個(gè)地方知識(shí)點(diǎn)挺多的,而且很重要,所以,今天添加一點(diǎn)小筆記。

長按 : on-hold

在屏幕同一位置按住超過500ms,將觸發(fā)on-hold事件:

 你可以在任何元素上使用這個(gè)指令掛接監(jiān)聽函數(shù):

<any on-hold=“…”>…</any>

示例代碼:

<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive” on-hold=”show_delete();”>
<h1 class=”title”>on-hold</h1>
</ion-header-bar>
<ion-content>
<ion-list ng-repeat=”item in items”>
<ion-item>
{{item}}
<ion-delete-button class=”ion-minus-circled”></ion-delete-button>
<ion-reorder-button class=”ion-navicon”></ion-reorder-button>
</ion-item>
</ion-list>
</ion-content>
<ion-footer-bar class=”bar-positive”></ion-footer-bar>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope, $ionicListDelegate) {
$scope.items=[“China”,”Japan”,”India”,”Russian”];
$scope.show_delete = function(){
$ionicListDelegate.showDelete(true);
};
});

敲擊 : on-tap

在屏幕上快速點(diǎn)擊一次(停留時(shí)間不超過250ms),將觸發(fā)on-tap事件:

可以在任何元素上使用這個(gè)指令掛接事件監(jiān)聽函數(shù):

<any on-tap=“…”>…</any>

示例代碼:

<head>
<meta name=”viewport” content=”initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width,height=device-height”>
<script src=”ionic.bundle.min.js”></script>
<link rel=”stylesheet” type=”text/css” href=”ionic.min.css”>
</head>
<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive”>
<h1 class=”title”>on-tap</h1>
</ion-header-bar>
<ion-content>
<ion-list ng-repeat=”item in items”>
<ion-item on-tap=”show(item);”>
{{item}}
<ion-reorder-button class=”ion-navicon”></ion-reorder-button>
</ion-item>
</ion-list>
</ion-content>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope, $ionicPopup) {
$scope.items=[“England”,”Japan”,”India”,”Russian”];
$scope.show = function(item){
$ionicPopup.alert({
title : “警告!”,
template : “為什么要敲 “+ item + “?”
});
};
});

雙擊 : on-double-tap
在屏幕上快速敲擊兩次,將觸發(fā)on-double-tap事件:

可以在任何元素上使用這個(gè)指令掛接事件監(jiān)聽函數(shù):

<any on-double-tap=“…”>…</any>

示例代碼:

<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive” on-double-tap=”title='I am double tapped!'”>
<h1 class=”title”>{{title}}</h1>
</ion-header-bar>
<ion-content>
<p ng-include=”‘txt/xiyouji.txt'”></p>
</ion-content>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope) {
$scope.title = “on-double-tap”;
});

按下/松開 on-touch/on-release

在屏幕上按下手指或鼠標(biāo)鍵時(shí),會(huì)立即觸發(fā)on-touch事件;當(dāng)手指抬起或鼠標(biāo)鍵松開時(shí), 會(huì)立即觸發(fā)on-release事件。

可以在任何元素上掛接響應(yīng)的事件監(jiān)聽函數(shù):

<any on-touch=“…” on-release=“…”>…</any>

示例代碼:

<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive” ng-class=”[style]”
on-touch=”style='bar-assertive'” on-release=”style='bar-positive'”>
<h1 class=”title”>on-touche/on-release</h1>
</ion-header-bar>
<ion-content>
<img src=”img/0021.png”>
</ion-content>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope) {
});

拖拽 : on-drag

在屏幕上按住并移動(dòng)時(shí),觸發(fā)on-drag拖拽事件: 

根據(jù)運(yùn)動(dòng)方向的不同,可以細(xì)分為以下幾種事件:

  • on-drag – 向所有方向拖動(dòng)時(shí)都觸發(fā)此事件
  • on-drag-up – 向上拖動(dòng)時(shí)觸發(fā)此事件
  • on-drag-down – 向下拖動(dòng)時(shí)觸發(fā)此事件
  • on-drag-left – 向左拖動(dòng)時(shí)觸發(fā)此事件
  • on-drag-right – 向右拖動(dòng)時(shí)觸發(fā)此事件

可以在任意元素上使用這些指令掛接對(duì)應(yīng)的事件監(jiān)聽函數(shù):

<any on-drag=“…”>…</any>

示例代碼:

<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive”>
<h1 class=”title”>on-drag</h1>
</ion-header-bar>
<div class=”scroll-content has-header padding”>
<img src=”img/baymax.png” on-touch=”onTouch($event)” on-drag=”onDrag($event);”>
</div>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope) {
var ox,oy;
$scope.onTouch = function($event){
ox = $event.target.offsetLeft;
oy = $event.target.offsetTop;
};
$scope.onDrag = function($event){
var el = $event.target,
dx = $event.gesture.deltaX,
dy = $event.gesture.deltaY;
el.style.left = ox + dx + “px”;
el.style.top = oy + dy + “px”;
};
});

劃動(dòng) : on-swipe

在屏幕上按住并快速拖動(dòng)時(shí),將觸發(fā)on-swipe劃動(dòng)事件:

根據(jù)劃動(dòng)方向的不同,可細(xì)分為以下指令:

  • on-swipe – 向任何方向的劃動(dòng)都觸發(fā)事件
  • on-swipe-up – 向上劃動(dòng)時(shí)觸發(fā)事件
  • on-swipe-down – 向下劃動(dòng)時(shí)觸發(fā)事件
  • on-swipe-left – 向左劃動(dòng)時(shí)觸發(fā)事件
  • on-swipe-right – 向右劃動(dòng)時(shí)觸發(fā)事件

可以在任何元素上使用這些指令掛接事件監(jiān)聽函數(shù):

<any on-swipe=“…”>…</any>

示例代碼:

<body ng-controller=”ezCtrl”>
<div class=”scroll-content padding”
on-swipe-up=”onSwipeUp()”
on-swipe-down=”onSwipeDown()”
on-swipe-left=”onSwipeLeft()”
on-swipe-right=”onSwipeRight()”>
<p class=”padding”>按住鼠標(biāo)快速劃!</p>
<i class=”icon {{icon}}”></i>
</div>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope){
$scope.icon=”ion-arrow-expand”;
$scope.onSwipeUp = function(){
$scope.icon=”ion-arrow-up-a”;
};
$scope.onSwipeDown = function(){
$scope.icon=”ion-arrow-down-a”;
};
$scope.onSwipeLeft = function(){
$scope.icon=”ion-arrow-left-a”;
};
$scope.onSwipeRight = function(){
$scope.icon=”ion-arrow-right-a”;
};
});

腳本接口 : $ionicGesture

除了使用之前介紹的特定指令實(shí)現(xiàn)手勢(shì)事件的監(jiān)聽,也可以使用$ionicGesture服務(wù) 注冊(cè)/解除手勢(shì)事件監(jiān)聽:

on(eventType,callback,$element,options) – 注冊(cè)手勢(shì)事件監(jiān)聽函數(shù)

參數(shù)eventType是支持的事件類型,參看下面介紹;參數(shù)callback指定監(jiān)聽函數(shù); 參數(shù)$element是要綁定事件的jqLite元素。

on()方法返回的是一個(gè)ionic.gesture對(duì)象,可供解除監(jiān)聽用。

off(gesture,eventType,callback) – 解除手勢(shì)事件監(jiān)聽函數(shù)

參數(shù)gesture是on()方法返回的結(jié)果對(duì)象,參數(shù)callback是要移除的監(jiān)聽函數(shù)。

$ionicGesture服務(wù)支持的事件類型有:

hold, tap, doubletap, drag, dragstart, dragend, dragup, dragdown, dragleft, dragright, swipe, swipeup, swipedown, swipeleft, swiperight, transform, transformstart, transformend, rotate, pinch, pinchin, pinchout, touch, release

示例代碼:

<body ng-controller=”ezCtrl”>
<ion-header-bar class=”bar-positive”>
<h1 class=”title”>$ionicGesture</h1>
</ion-header-bar>
<ion-content class=”padding”>
<button class=”button” id=”test”>test</button>
</ion-content>
</body>

js:

angular.module(“ezApp”,[“ionic”])
.controller(“ezCtrl”,function($scope,$ionicGesture,$ionicPopup) {
var el = document.querySelector(“#test”);
$ionicGesture.on(“tap”,function(){
$ionicPopup.alert({
title : “提醒”,
template : “這個(gè)監(jiān)聽是用$ionicGesture服務(wù)注冊(cè)的!”
})
},angular.element(el));
});

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Angular的數(shù)據(jù)顯示優(yōu)化處理

    詳解Angular的數(shù)據(jù)顯示優(yōu)化處理

    本文主要對(duì)Angular的數(shù)據(jù)顯示優(yōu)化處理進(jìn)行詳細(xì)介紹,具有一定的參考價(jià)值,下面跟著小編一起來看下吧
    2016-12-12
  • 實(shí)例剖析AngularJS框架中數(shù)據(jù)的雙向綁定運(yùn)用

    實(shí)例剖析AngularJS框架中數(shù)據(jù)的雙向綁定運(yùn)用

    這篇文章主要介紹了AngularJS框架中數(shù)據(jù)的雙向綁定運(yùn)用實(shí)例,包括數(shù)據(jù)綁定中的關(guān)鍵函數(shù)與監(jiān)聽器觸發(fā)的相關(guān)講解,需要的朋友可以參考下
    2016-03-03
  • angularjs實(shí)現(xiàn)時(shí)間軸效果的示例代碼

    angularjs實(shí)現(xiàn)時(shí)間軸效果的示例代碼

    本篇文章主要介紹了angularjs實(shí)現(xiàn)時(shí)間軸效果的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • angular.extend方法的具體使用

    angular.extend方法的具體使用

    本篇文章主要介紹了angular.extend方法的具體使用,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-09-09
  • AngularJS 單元測(cè)試(二)詳解

    AngularJS 單元測(cè)試(二)詳解

    這篇文章主要介紹了AngularJS 單元測(cè)試(二)的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • 基于angularJS的表單驗(yàn)證指令介紹

    基于angularJS的表單驗(yàn)證指令介紹

    下面小編就為大家?guī)硪黄赼ngularJS的表單驗(yàn)證指令介紹。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2016-10-10
  • 最棒的Angular2表格控件

    最棒的Angular2表格控件

    最好的Angular2表格控件,滿足更小、更快、更熟悉的基本要求,感興趣的小伙伴們可以參考一下
    2016-08-08
  • 詳解創(chuàng)建自定義的Angular Schematics

    詳解創(chuàng)建自定義的Angular Schematics

    本文對(duì) Angular Schematics 進(jìn)行了介紹,并創(chuàng)建了一個(gè)用于創(chuàng)建自定義 Component 的 Schematics ,然后在 Angular 項(xiàng)目中以它為模板演練了通過 Schematics 添加自定義的 Component,感興趣的小伙伴們可以參考一下
    2018-06-06
  • AngularJS select加載數(shù)據(jù)選中默認(rèn)值的方法

    AngularJS select加載數(shù)據(jù)選中默認(rèn)值的方法

    下面小編就為大家分享一篇AngularJS select加載數(shù)據(jù)選中默認(rèn)值的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-02-02
  • angular forEach方法遍歷源碼解讀

    angular forEach方法遍歷源碼解讀

    這篇文章主要為大家詳細(xì)了angular forEach方法遍歷源碼,forEach()方法用于遍歷對(duì)象或數(shù)組,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01

最新評(píng)論