如何触摸滚动?
我有一个组件,其中应禁用touchmove
事件。我尝试了以下内容,但它不起作用。
parentRef.current.addEventListener("touchMove", e => e.preventDefault(), false)
I have a component in react on which touchmove
event should be disabled. I have tried the following but it does not work.
parentRef.current.addEventListener("touchMove", e => e.preventDefault(), false)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以简单地使用 touch-action> touch-action 您的CSS文件以从HTML主体或元素中删除滚动事件。在您的代码中添加以下代码。
You can simply use the touch-action property in your CSS file to remove the scroll event from your html body or an element. Add the below code in your code.
您可以检查此设备是否在某些像素以下的内部宽度,然后设置
溢出:隐藏
和height&宽度到100VH
&100VW
分别在使用effect的parentrefYou can check if this device has innerWidth below certain pixels then set
overflow:hidden
and height & width to100vh
&100vw
respectively to the parentRef in useEffect为了防止在React渲染的组件上使用CSS滚动,我们可以将Overflow CSS属性设置为使用JavaScript隐藏。
例如,我们写入:
将车身元素的溢出CS设置为隐藏时,当组件安装时:
使用效率回调仅在组件安装时才运行,因为我们以空数组作为使用效果的第二个参数。
To prevent scrolling using CSS on React rendered components, we can set the overflow CSS property to hidden with JavaScript.
For instance, we write:
to set the overflow CSS of the body element to hidden when the component mounts with:
The useEffect callback only runs when the component mounts since we passed in an empty array as the 2nd argument of useEffect.