gpt4 book ai didi

javascript - iOS 11.4 Safari 不遵守 'touch-action: manipulation'

转载 作者:可可西里 更新时间:2023-11-01 05:48:38 27 4
gpt4 key购买 nike

我在尝试构建跨平台的 React 网络应用程序时遇到问题。基本上,我只是想通过在桌面上双击和在移动设备上双击来与 div 进行交互。

但是,在 iOS 上(我特别针对最新的 11.4 版本的 Safari),双击总是会导致“双击缩放”行为。

根据我的研究,我发现在我的 css 中使用 touch-action: manipulation 应该可以解决这个问题,而且 iOS 上的 Safari 甚至应该支持它 (https://caniuse.com/#feat=css-touch-action)。

但是,我做了一个 super 简单的 React 元素,无论如何,双击蓝色 div 总是会缩放。

我希望我只是遗漏了一些东西,所以如果有人能启发我,我将不胜感激!

这是我在 GitHub 上托管的 super 简单的 React 元素:https://github.com/erlloyd/touch-action-bug ,这是相关代码:

应用组件

import React, { Component } from 'react';
import './App.css';

class App extends Component {
render() {
return (
<div className="App">
</div>
);
}
}

export default App;

应用.css

.App {
width: 100px;
height: 100px;
margin-left: 10px;
margin-top: 10px;
background: blue;
touch-action: manipulation;
}

相关标签:

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

最佳答案

原版的最后几条评论WebKit feature request可能对您有用。

...what's happening in that example is that since the touch-action: manipulation div is not clickable, we skip that node when trying to find a clickable element for the touch. To verify this, add an onclick to the div with touch-action manipulation and touches on it should turn fast.

This page显示该属性似乎在对象可单击时适用,并且在测试中我可以看到双击缩放行为不会发生在“操纵”框上。

将 onClick 添加到您的 div 应该可以解决问题,例如:

class App extends Component {
render() {
return (
<div className="App" onClick={e => e.preventDefault()}>
</div>
);
}
}

关于javascript - iOS 11.4 Safari 不遵守 'touch-action: manipulation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51600527/

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