How to implement swipe in ionic using HammerJs?

yshnv
Marvenics
Published in
1 min readAug 2, 2019

Hello,

Hammer Js is used to add touch gestures to your web app. In Ionic Framework, we can add swipeable gestures bu using Hammer Js

Setup

First, install Hammer Js

npm install –save hammerjs

After Installation generates a class file using CMD

ionic g class HammerConfig

It will generate a class file called HammerConfig.ts

In HammerConfig.ts Class should have the following definition

And register MyHammerConfig Class in app.module.ts

{ provide: HAMMER_GESTURE_CONFIG, useClass: MyHammerConfig }

Add this line to the Providers section in app.module.ts.

import {MyHammerConfig} from ‘../HammerConfig’;

And import MyHammerConfig in the import section.

You can find the gestures which Hammer Js provide from Here.

For Example

<div(pan)=”onPan($event)”></div>

onPan(event){

console.log(event);

}

You can refer to is live stackblitz project

Thanks :)

--

--

yshnv
Marvenics

Angular | Ionic Framework | ExpressJS | UIUX