gpt4 book ai didi

angular - HammerJS 滑动不适用于具有溢出 css 属性的元素

转载 作者:行者123 更新时间:2023-12-03 08:48:49 25 4
gpt4 key购买 nike

编辑:该代码片段在嵌入问题时工作正常,但在编辑时则不然;这让我意识到这与可以滚动的底层容器有关...我在手机上测试了这一点,锤子在没有 overflow 属性的小区域上工作得很好。
我更新了代码片段以反射(reflect)这一点。

问题是:如何让它在需要垂直滚动的容器上工作?


我正在 Angular PWA 中构建滑动导航。我可以在 Chrome 桌面上使用它,但在我的手机上却无法使用。当我在 Chrome 开发工具中尝试触摸模拟器时,它根据方向/设备而变得疯狂,大多数情况下根本没有检测到任何东西。 panleftpanright 工作得稍微好一些,但由于某种原因完全破坏了锤子(可能是因为我没有对它进行去抖,它只是在不久之后停止检测而没有任何错误)。

我做错了什么?

在 Chrome 开发工具中与设备模拟器一起使用时,下面的代码片段的行为类似

const hammer = new Hammer(document.documentElement);
hammer.on('swipeleft swiperight', event => {
console.log(event.type);
});
body,
html {
height: 100%;
}

.content {
margin-top: 20%;
width: 100%;
height: 80%;
background: orange;
overflow-y: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
Can touch this
<div class="content">Can't touch this (on mobile / emulator)</div>

实际代码

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(
private gameService: GameService,
private routerService: RouterService
) {}

ngOnInit() {
this.gameService.gameInit();

const hammer = new Hammer(document.documentElement);
hammer.on('swipeleft swiperight', event => {
if (event.type === 'swiperight') {
this.routerService.navNext();
} else if (event.type === 'swipeleft') {
this.routerService.navPrev();
}
});
}
}

最佳答案

正确的答案是将 touch-action: pan-y !important 粘贴到具有溢出属性的类中

关于angular - HammerJS 滑动不适用于具有溢出 css 属性的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60198150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com