为什么更改 canvas 大小会重置其参数?
Why changing canvas size resets its parameters?
当我更改 canvas 大小时,我注意到参数 'mozImageSmoothingEnabled' 正在重置。
HTML
<canvas id='canv'>Your browser don't support canvas.</canvas>
Javascript
var cnv = document.getElementById('canv');
var ctx = cnv.getContext('2d');
console.log(ctx.mozImageSmoothingEnabled); // default 'true'
ctx.mozImageSmoothingEnabled = false;
console.log(ctx.mozImageSmoothingEnabled); // shows 'false'
cnv.width = 100;
console.log(ctx.mozImageSmoothingEnabled); // shows 'true'
JSFiddle:https://jsfiddle.net/epvtuz37/
这是错误还是预期行为?
因为当您更改 canvas width
或 height
参数时,附加上下文的 every 属性将重置为其默认值。
When the canvas element is created, and subsequently whenever the width and height attributes are set (whether to a new value or to the previous value), the bitmap and any associated contexts must be cleared back to their initial state and reinitialized with the newly specified coordinate space dimensions.
当我更改 canvas 大小时,我注意到参数 'mozImageSmoothingEnabled' 正在重置。
HTML
<canvas id='canv'>Your browser don't support canvas.</canvas>
Javascript
var cnv = document.getElementById('canv');
var ctx = cnv.getContext('2d');
console.log(ctx.mozImageSmoothingEnabled); // default 'true'
ctx.mozImageSmoothingEnabled = false;
console.log(ctx.mozImageSmoothingEnabled); // shows 'false'
cnv.width = 100;
console.log(ctx.mozImageSmoothingEnabled); // shows 'true'
JSFiddle:https://jsfiddle.net/epvtuz37/
这是错误还是预期行为?
因为当您更改 canvas width
或 height
参数时,附加上下文的 every 属性将重置为其默认值。
When the canvas element is created, and subsequently whenever the width and height attributes are set (whether to a new value or to the previous value), the bitmap and any associated contexts must be cleared back to their initial state and reinitialized with the newly specified coordinate space dimensions.