Skip to content

Instantly share code, notes, and snippets.

@wsd1
Last active January 24, 2019 13:14
Show Gist options
  • Save wsd1/4bc8c121bee064fd767cbade7f2c1e45 to your computer and use it in GitHub Desktop.
Save wsd1/4bc8c121bee064fd767cbade7f2c1e45 to your computer and use it in GitHub Desktop.
通过 window.innerWidth 和css填充canvas满屏的方法
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