【问题标题】:HammerJS Swipe not working on Mobile Device or Google Chrome on Device ModeHammerJS Swipe 在移动设备或设备模式下的 Google Chrome 上不起作用
【发布时间】:2019-10-09 07:23:35
【问题描述】:

我有一个简单的代码可以让网站可滑动,当我在桌面版 Google Chrome 上测试时它可以工作,但是当我要在我的移动设备上或在 Google Chrome DevTools 设备模式上进行测试时它就不起作用了。

我尝试更改 HammerGestureConfig 覆盖的值,但当我尝试更改为 swipeleft 或 swiperight 时出现错误,只接受滑动覆盖。

...
import * as Hammer from 'hammerjs';
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG, BrowserModule } from '@angular/platform-browser';
import { SwipeComponent } from './components/swipe/swipe.component';

export class HammerConfig extends HammerGestureConfig {
  overrides = {
    swipe: { direction: Hammer.DIRECTION_ALL },
  } as any;
}

@NgModule({
  declarations: [
    ...
    SwipeComponent,
  ],
  ...
  providers: [
    AuthService,
    {
      provide: HAMMER_GESTURE_CONFIG,
      useClass: HammerConfig
    }
  ],
})
export class AppModule { }

<div
  (swipeleft)="navigateForwardTo(forward)"
  (swiperight)="navigateBackTo(back)">
  <ng-content></ng-content>
  <app-navigation-arrows 
    [back]="back"
    [backEnabled]="backEnabled"
    [forwardEnabled]="forwardEnabled"
    [forward]="forward">
  </app-navigation-arrows>
</div>

【问题讨论】:

    标签: angular google-chrome google-chrome-devtools hammer.js


    【解决方案1】:

    我不得不将 inputClass 更改为 Hammer.TouchInput

    export class HammerConfig extends HammerGestureConfig  {
      buildHammer(element: HTMLElement): HammerManager {
         return new Hammer.Manager(element, {
          touchAction: 'auto',
          inputClass: Hammer.TouchInput,
          recognizers: [
            [Hammer.Swipe, {
              direction: Hammer.DIRECTION_HORIZONTAL
            }]
          ]
        });
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2022-01-12
      • 2014-04-22
      • 1970-01-01
      相关资源
      最近更新 更多