2017-02-16 61 views
0

我在寻找absolute screen scale的值。访问绝对屏幕比例值

例如,当绑定到gestureend事件,就可以访问到event.scale数据这是1的周围:

  1. case: scale > 1放大
  2. case: scale < 1缩小

这个数据,而不是绝对的,是相对于事件触发前的状态。

例如:

  • 用户放大到一定程度(比方说)2
  • ,则用户缩小到一定程度(比方说)1.8。 最后,结果将是视口仍然被缩放,但scale value将是< 1

所以,我的问题是,我怎样才能访问absolute zoom scale值?换句话说,如何比较scale value而不是initial scale value

回答

0

我想通了这种方式:

function getCurrentScale() { 
    return document.documentElement.clientWidth/window.innerWidth; 
} 

const INITIAL_SCALE = getCurrentScale(); 
let lastScale = INITIAL_SCALE; 

document.addEventListener('gestureend',() => { 
    let currentScale = getCurrentScale(); 

    console.log("scale", { 
    initial: INITIAL_SCALE, 
    last: lastScale, 
    current: currentScale 
    }); 

    lastScale = currentScale; 
});