@huangjs888/load-image
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

loadImage

图片加载封装,带有进度的

安装使用

npm install @huangjs888/load-image --save

使用方法

import loadImage from '@huangjs888/load-image';

// 第二个参数为progress函数,传入,则使用ajax获取图片资源(ajax方式不适合跨域获取图片),不传,则直接Image对象
loadImage('http://xx/xxx/xx.jpg', (v) => {
  document.body.innerHTML = `<span>加载进度:${v * 100}%</span>`;
})
  .then((image) => {
    image.width = image.naturalWidth;
    image.height = image.naturalHeight;
    document.body.appendChild(image);
  })
  .catch(() => {
    document.body.innerHTML = '<span>加载图片失败!</span>';
  });

  

Package Sidebar

Install

npm i @huangjs888/load-image

Weekly Downloads

3

Version

1.2.2

License

MIT

Unpacked Size

733 kB

Total Files

9

Last publish

Collaborators

  • huangjs888