HTMLImageElement.decoding

HTMLImageElement 接口的 decoding 属性用于告诉浏览器使用何种方式解析图像数据。

Syntax

refStr = imgElem.decoding;
imgElem.decoding = refStr;

Values

使用 DOMString 表示解码方式. 可使用以下值:

  • sync: 同步解码图像,保证与其他内容一起显示。
  • async: 异步解码图像,加快显示其他内容。
  • auto: 默认模式,表示不偏好解码模式。由浏览器决定哪种方式更适合用户。

Usage notes

decoding 属性使您可以控制是否允许浏览器尝试异步加载图像。如果这样做会引起问题,您可指定值为 sync 禁止异步加载。异步加载对 <img> 元素很有用,对屏幕外的图像对象可能会更有用。

Examples

var img = new Image();
img.decoding = 'sync';
img.src = 'img/logo.png'; 

Specifications

Specification Status Comment
HTML Living Standard
decoding
Living Standard

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
decodingChrome Full support 65Edge Full support ≤79Firefox Full support 63IE No support NoOpera Full support YesSafari Full support 11.1WebView Android Full support 65Chrome Android Full support 65Firefox Android Full support 63Opera Android ? Safari iOS Full support 11.3Samsung Internet Android Full support 9.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown