WebGLRenderingContext.drawingBufferWidth

WebGLRenderingContext.drawingBufferWidth 只读属性, 指示当前绘图缓冲区的实际宽度。它应当匹配与绘图上下文相关联的 <canvas> 元素的宽度属性。如果实现未能提供所要求的宽度,值将有所不同。

语法

gl.drawingBufferWidth;

示例

指定<canvas> 元素:

<canvas id="canvas"></canvas>

你可以通过下面几行代码来获取绘图缓冲区的宽度:

var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
gl.drawingBufferWidth; // 300

规范

Specification Status Comment
WebGL 1.0
WebGLRenderingContext.drawingBufferWidth
Recommendation Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
drawingBufferWidthChrome Full support 9Edge Full support 12Firefox Full support 4IE Full support 11Opera Full support 12Safari Full support 5.1WebView Android Full support YesChrome Android Full support 25Firefox Android Full support YesOpera Android Full support 12Safari iOS Full support 8Samsung Internet Android Full support Yes

Legend

Full support  
Full support

相关链接