小编Lui*_*ana的帖子

HammerJS Swipe 无法在移动设备或设备模式下的 Google Chrome 上运行

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

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

...
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 { }

Run Code Online (Sandbox Code Playgroud)
<div …
Run Code Online (Sandbox Code Playgroud)

google-chrome google-chrome-devtools hammer.js angular

3
推荐指数
1
解决办法
2036
查看次数