Giter VIP home page Giter VIP logo

darrell-photo-gallery's Introduction

darrell-photo-gallery

因为最近工作需要预览制作一个图片预览的插件,在查看了很多产品(掘金、知乎、简书、石墨等)的图片预览之后,还是觉得石墨的图片预览符合我们的产品需求。

介绍

这是一个基于 React Hoos 开发的 仿石墨的图片 放大预览插件。

在社区找了很久之后,没有找到相关的轮子,于是自己撸了一个。

插件的功能是当你的设备支持 canvas 的时候,就使用 canvas 进行绘图,当不支持 canvas 的时候就直接显示图片。

支持功能

  • 放大图片
  • 缩小图片
  • 原尺寸大小显示
  • 适应屏幕
  • 下载图片

预览

安装

// 安装
npm install darrell-photo-gallery -D

// 在项目中使用

import PhotoGallery from 'darrell-photo-gallery';
import 'darrell-photo-gallery/lib/main.min.css';

使用

<PhotoGallery
 visible={visible}
 imgData={ImgData}
 currentImg = {9}
 hideModal={
  () => {
    setVisible(false);
  }
 }
/>

目前支持四个参数:

  • visibleboolean,预览插件的显示隐藏

  • imgDataobject,具体属性如下

    interface Img {
      url: string;
      size?: string;
      width?: string;
      height?: string;
      [propName: string]: any;
    }
  • currentImgnumber,当前图片在图片数组中是第几张

  • hideModalhideModal?(): void;,是一个函数,关闭图片预览弹窗

 

原理介绍

原理介绍大家可以移步笔者的掘金文章:使用 React Hooks 实现仿石墨的图片预览插件(巨详细)

darrell-photo-gallery's People

Contributors

darrell0904 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.