Canvas Detect Pixel Ratio 侦测像素比 - caleb531/jcanvas-docs GitHub Wiki

Detect Pixel Ratio 侦测像素比

jCanvas offers a detectPixelRatio() method for detecting high-resolution displays (including devices with retina displays).
jCanvas提供了一个detectPixelRatio()方法来侦测高分辨率显示(包括视网膜显示器)。
For these devices, the method will increase the dimensional width and height of the canvas, scale its context to match, then scale it down using CSS. This will result in the device rendering the canvas at a higher pixel density.
对于这些设备,本方法会提高画布的宽高维度,缩放画布语境以匹配,然后使用CSS来降低(应该是画布尺寸)。这会导致设备以较高像素密度来渲染画布。
The method also accepts a callback function as its only argument, which, in turn, accepts the device's pixel ratio as its only argument.
本方法也接收一个回调函数作为其唯一参数,这个回调函数接收设备的像素比作为其唯一参数。

$('canvas').detectPixelRatio(function(ratio) {
  // Run some code depending on the device pixel ratio
  // 依照设备像素比来运行一些代码
});

Notes 注意

Retina displays on Apple devices have a pixel ratio of 2.
苹果设备上的视网膜显示器像素比为2。