Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

异步解码图片 #31

Open
hfc-advance opened this issue Oct 30, 2018 · 0 comments
Open

异步解码图片 #31

hfc-advance opened this issue Oct 30, 2018 · 0 comments

Comments

@hfc-advance
Copy link
Owner

hfc-advance commented Oct 30, 2018

异步 decode

图片展示屏幕上会有一个 decode(解码)的过程,如果是大图片的话,解码速度会相当慢。由于解码是同步的,所有这个时候主线程会被阻塞,从来没法完成任何操作。所以就需要异步解码图片。

function prepareImage() {
  var img = new Image();
  img.src = "nebula.jpg";
  img.decode().then(function() { document.body.appendChild(img); });
}

或者使用 async属性

// 打开异步解码
<img async=on src="space.jpg"  >

//关闭异步解码
<img async=off src="space.jpg">

使用异步 decode 将不会阻塞主线程
异步:
result
同步:
result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant