Screen Resolution On A PhoneGap App

前端 未结 3 1598
悲&欢浪女
悲&欢浪女 2020-12-30 07:29

I\'m writing a Phonegap (3.2) app, I take a HTML5 canvas, make it full screen and the whole app UI is on this canvas.

Using a Samsung Galaxy S4 (Android 4.3) to test

3条回答
  •  萌比男神i
    2020-12-30 07:51

    Try something like this:

    var windowWidth = window.innerWidth;
    var windowHeight = window.innerHeight;
    var pixelRatio = window.devicePixelRatio || 1; /// get pixel ratio of device
    
    canvasMain = document.getElementById("canvasSignatureMain");
    
    canvasMain.width = windowWidth * pixelRatio;   /// resolution of canvas
    canvasMain.height = windowHeight * pixelRatio;
    
    canvasMain.style.width = windowWidth + 'px';   /// CSS size of canvas
    canvasMain.style.height = windowHeight + 'px';
    

    (or an absolute value for the css rule).

    On devices where the pixel ratio is higher than the typical 1:1 you get a higher resolution canvas. For normal circumstances everything is as normal.

提交回复
热议问题