1.2.2 • Published 12 months ago

qm-preview-image v1.2.2

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

qm-preview-image

Installation

npm install qm-preview-image

yarn add qm-preview-image

Usage

import { useState, useCallback } from 'react';
import img1 from '@/assets/images/1.jpg';
import img2 from '@/assets/images/2.jpg';
import img3 from '@/assets/images/3.jpg';
import img4 from '@/assets/images/4.jpg';
import img5 from '@/assets/images/5.jpg';
import PreviewImage from 'qm-preview-image';

const imgs = [img1, img2, img3, img4, img5];

export default function App() {
  const [visible, setVisible] = useState(false);
  const handleClose = useCallback(() => setVisible(() => false), []);
  return (
    <div>
      <button onClick={() => setVisible(true)>预览</button>

      <PreviewImage
        index={0}
        imgs={imgs}
        pageSize={9}
        open={visible}
        hasPerformance
        // 如果没有缩略图和高清图的区分,只要提供 imgs 就行了。
        // imgs 与 previewImgs 长度需要保持一致。
        // previewImgs 表示缩略图的集合,默认取 imgs。如果提供了 previewImgs,请将 hasPerformance 设置为 true。
        previewImgs={imgs}
        onClose={handleClose}
      />
    </div>
  );
}

props

paramdetailtypedefault
openwhether to display componentbooleanfalse
indexwhich image to preview by defaultnumber0
imgspicture collectionstring[][]
previewImgsprovide a collection of thumbnailsstring[]imgs
hasPerformancestart image performance optimizationbooleanfalse
onCloseclose the componentfunction-
pageSizeSpecify how many images can be displayed on a thumbnail pagenumber9

图像展示性能优化方案

图像展示性能优化方案是通过提供一个与 imgs 数组长度一样的 previewImgs 数组,previewImgs 数组中提供的是缩略图(低像素),同时,需要将 hasPerformance 设置为 true

在展示缩略图的同时浏览器在加载高清图,等高清图像下载完成后会自动切换成高清图像。

普通模式

qm-preview-image 组件同样也提供了普通的预览模式,只需要提供 imgs 数组对象即可,在预览时展示的就是 imgs 数组中提供的图像。

1.2.2

12 months ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago