0
更改html5畫布緩衝區大小即canvas.width和canvas.height在使用webgl時似乎會更改ios 8和ios 9上的畫布顯示大小,但在桌面瀏覽器中似乎正常: https://jsfiddle.net/psqvur80/更改html5畫布緩衝區大小和webgl
<html>
<head>
</head>
<body>
<div id="iv" style="width:400px;height:400px;"></div>
<script type="text/javascript">
var iv = document.getElementById('iv');
var test = function(){
this.canvas = document.createElement('canvas');
this.canvas.style.width = '100%';
this.canvas.style.height = '100%';
this.canvas.width = 200;
this.canvas.height = 200;
this.canvas.style.borderColor = 'red';
this.canvas.style.borderWidth = '2px';
this.canvas.style.borderStyle = 'solid';
iv.appendChild(this.canvas);
this.initWebGL();
}
test.prototype.initWebGL = function() {
// attempt to get a webgl context
try {
var gl = this.gl = this.canvas.getContext('webgl') || this.canvas.getContext('experimental-webgl');
} catch (e) {
return false;
}
};
var testcase = new test();
testcase.gl.viewport(0, 0, 200, 200);
testcase.gl.clearColor(0, 0.5, 0, 1);
testcase.gl.clear(testcase.gl.COLOR_BUFFER_BIT);
setTimeout(function(){
//console.log('resize');
testcase.gl.viewport(0, 0, 100, 100);
testcase.canvas.width = 100;
testcase.canvas.height = 100;
testcase.gl.clearColor(0, 0.5, 0, 1);
testcase.gl.clear(testcase.gl.COLOR_BUFFER_BIT);
}, 2000);
</script>
</body>
我試過視口設置,但沒有運氣。 我如何才能讓顯示dimentions同時改變畫布的緩衝區的大小?
好一個,圖像dimentions在序列有時會發生變化,所以畫布需要,我不知道如果計算明智這種方法比重新創建畫布本身不應觸發佈局更好更改。 – NTN