Vertical scroll is not working with HammerJS and Angular2

前端 未结 5 673
盖世英雄少女心
盖世英雄少女心 2021-02-02 08:01

I\'m having a problem using the HammerJS with Angular2. I have a carousel (based on the bootstrap carousel with Angular2 event handlers) where I\'m listening to the swip

5条回答
  •  旧巷少年郎
    2021-02-02 08:43

    This solution works for my Chrome 66 (Angular 6 app). Scrolling is enabled, swipe right/left works also:

    import {
      HammerGestureConfig,
      HAMMER_GESTURE_CONFIG
    } from '@angular/platform-browser';
    import * as Hammer from 'hammerjs';
    
    export class MyHammerConfig extends HammerGestureConfig {
      buildHammer(element: HTMLElement) {
        const mc = new Hammer(element, {
          touchAction: 'pan-y'
        });
    
        return mc;
      }
    }
    
    @NgModule({
        declarations: [
            // ...
        ],
        imports: [
            // ...
        ],
        providers: [
            // ...
            {
                provide: HAMMER_GESTURE_CONFIG,
                useClass: MyHammerConfig
            }
        ],
        bootstrap: [ AppComponent ]
    })
    export class AppModule {}
    

提交回复
热议问题