admin管理员组文章数量:1291009
How can I use swipe up
or swipe down
with Ionic 2?
I've tried the Gestures API but it only fires on horizontal swipe.
<ion-card (swipe)="swipePage($event)">
</ion-card>
How can I use swipe up
or swipe down
with Ionic 2?
I've tried the Gestures API but it only fires on horizontal swipe.
<ion-card (swipe)="swipePage($event)">
</ion-card>
Share
Improve this question
asked Feb 13, 2017 at 3:26
brians69brians69
4853 gold badges12 silver badges26 bronze badges
2 Answers
Reset to default 13In the HammerJS official document, bottom line says :
When calling Hammer() to create a simple instance, the pan and swipe recognizers are configured to only detect horizontal gestures.
For additional config, you must tweak your hammer instance, try this :
First run
npm install hammerjs --save && npm install @types/hammerjs --save-dev
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import * as Hammer from 'hammerjs';
// create a class that overrides hammer default config
export class MyHammerConfig extends HammerGestureConfig {
overrides = <any>{
'swipe': { direction: Hammer.DIRECTION_ALL } // override default settings
}
}
// In your module providers, add this :
providers: [{
provide: HAMMER_GESTURE_CONFIG,
useClass: MyHammerConfig
}]
For Ionic 5+,
Install Hammerjs using npm install --save hammerjs @types/hammerjs
Then, on app.module.ts
, HammerModule and BrowserModule like so:
import { BrowserModule, HammerModule } from '@angular/platform-browser';
Then, within the imports array, add HammerModule, and of course, BrowserModule that es as default.
Like so: imports: [BrowserModule, HammerModule,...]
Then, go to main.ts
file and add import 'hammerjs';
If your project is being served using ionic serve
, disconnect it and reconnect, to initialize your update.
To call the swipe events on your page, use (pan) or (swipe) events like so:
//home.page.html
<div (pan)="swipeEvent($event)"></div>
//home.page.ts
swipeEvent(e){
swipeDirection = e.direction;
console.log('Swipe',swipeDirection);
//2 = left;
//4 = right;
//8 = top;
//16 = down;
}
本文标签: javascriptSwipe updown not working on Ionic 2Stack Overflow
版权声明:本文标题:javascript - Swipe updown not working on Ionic 2 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741511366a2382628.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论