Last active
January 24, 2019 13:14
-
-
Save wsd1/4bc8c121bee064fd767cbade7f2c1e45 to your computer and use it in GitHub Desktop.
通过 window.innerWidth 和css填充canvas满屏的方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function adjust(canvas, rw, rh) { | |
var width = window.innerWidth; | |
//var ratio = rw / rh; //canvas.width / canvas.height; | |
//var height = width / ratio; | |
if(!rw){ | |
rw = canvas.width | |
rh = canvas.height | |
} | |
var height = width * rh / rw ; | |
canvas.style.width = width + 'px'; | |
canvas.style.height = height + 'px'; | |
} | |
adjust(canvas, 4, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment