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

标签 javascript html ios css reactjs

我在尝试构建跨平台的 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/

相关文章:

javascript - html5 <audio> 播放时用javascript设置边框颜色

javascript - 在 Javascript 中构建对象原型(prototype)会破坏 jQuery?

javascript - 像处理 JS 窗口对象一样处理 div 的边缘

android - 在Android应用程序中播放YouTube视频的最适应方式

ios - 多个DCSliders发送不同的控制值(Xcode)

ios - Xcode 6 这么多模拟器困惑

javascript - $ ("element").remove();在 iframe 中使用 jquery

html - 将 3D 内容与网站集成有哪些技术?

javascript - 在上下文创建阶段提升如何工作

ios - AudioQueue 得到错误数量的数据包?