HTMLImageElement.decode()

这篇翻译不完整。请帮忙从英语翻译这篇文章

api用于dom原生
decode方法返回一个promise对象,当图片解析完毕,安全的插入dom对象。能够快速准确的在图片加载完毕后处理图片,类似于onload

语法

var promise = HTMLImageElement.decode();

参数

无.

返回

promise对象.

额外

当加载发生错误时,使用一个EncodingError参数的方法,捕获错误

使用范围

具体看因为文档,大致意思,适用于懒加载

例子

const img = new Image();
img.src = 'nebula.jpg';
img.decode()
.then(() => {
  document.body.appendChild(img);
})
.catch((encodingError) => {
  // Do something with the error.
})

Specifications

Specification Status Comment
HTML Living Standard
decode()
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
decode()Chrome Full support 64Edge ? Firefox Full support 68IE ? Opera Full support YesSafari Full support 11.1WebView Android Full support 64Chrome Android Full support 64Firefox Android Full support 68Opera Android ? Safari iOS Full support 11.3Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

文档标签和贡献者

此页面的贡献者: LittleGhost
最后编辑者: LittleGhost,