标签:rip javascrip script 图片优化 完成 pre span src ati
我们可以将图片的加载写成一个promise,一旦加载完成,promise的状态就发生变化
const preloadImage = function (path) {
return new Promise(function (resolve, reject) {
const image = new Image();
image.onload = resolve;
image.onerror = reject;
image.src = path;
});
};
标签:rip javascrip script 图片优化 完成 pre span src ati
原文地址:https://www.cnblogs.com/lijinxiao/p/14537634.html