本文介绍了禁用webkit(或电子)中的捏缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在应用程式中停用缩放吗?



我无法使用正常的javascript方法从web视图中工作,如下所述:



似乎 - disable-pinch a href =https://github.com/atom/electron/blob/master/docs/api/chrome-command-line-switches.md>不受电子支持。



我已经尝试过各种方法使用:


  1. event.preventDefault 在javascript touchmove / mousemove 活动

  2. meta viewport 标签

  3. -webkit-text-size-adjust flags / config for electron

对于webkit有一般的方法,或)。因为smart上的智能缩放仍然使用document.addEventListener。



示例 require('electron')。webFrame.setZoomLevelLimits(1,1) / code>






UPDATE:



deltaY 属性用于缩放缩放具有 float 值,但正常滚动事件返回 int value。现在解决方案与ctrl键没有问题。



  document.addEventListener('mousewheel',function(e){
if(e.ctrlKey){
.preventDefault();
}
});


Is there any way to disable pinch zoom in an electron app?

I can't get it to work from inside the web-view with normal javascript methods as described here: http://stackoverflow.com/a/23510108/665261

It seems the --disable-pinch flag is not supported by electron.

I have experimented with various methods using:

  1. event.preventDefault() on javascript touchmove/mousemove events
  2. meta viewport tags in HTML
  3. -webkit-text-size-adjust in CSS
  4. flags/config for electron

Is there any method either for webkit in general, or electron in particular?

解决方案

UPDATE 2:

Use webFrame.setZoomLevelLimits (v0.31.1+) in render process (Differences Between Main Process and Renderer Process). Because smart zoom on mac still work with document.addEventListener.

Example require('electron').webFrame.setZoomLevelLimits(1, 1)


UPDATE:

deltaY property for pinch zoom has float value, but normal scroll event return int value. Now solution has no problem with ctrl key.

Demo 2.

document.addEventListener('mousewheel', function(e) {
  if(e.deltaY % 1 !== 0) {
    e.preventDefault();
  }
});


Using Chromium monitorEvents(document) I found that is responsible for this event mousewheel. I don't know, why mousewheel triggered with pinch zoom.Next step, find difference between normal scroll and pinch zoom.

Pinch zoom has an attribute e.ctrlKey = true, and normal scroll event has e.ctrlKey = false. But if you hold down ctrl key and scroll a page, e.ctrlKey equal true.

I couldn't find a better solution. :(

Demo

document.addEventListener('mousewheel', function(e) {
  if(e.ctrlKey) {
    e.preventDefault();
  }
});

这篇关于禁用webkit(或电子)中的捏缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:39