react-image-lightbox

React-Image-Lightbox是一个可靠的React组件,用于图片预览,具有键盘快捷键、图像缩放、灵活渲染和移动端优化功能,如pinch-to-zoom和swipe。它拥有上千颗星星和大量下载,适用于构建用户友好的图片库。
摘要由CSDN通过智能技术生成

react-image-lightbox

用途

react 中图片预览

可靠性

1K星星,上万下载,基本没问题

官网链接

https://www.npmjs.com/package/react-image-lightbox

https://github.com/frontend-collective/react-image-lightbox

https://frontend-collective.github.io/react-image-lightbox/

基本使用

import React, { Component } from 'react';
import Lightbox from 'react-image-lightbox';
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app

const images = [
  '//placekitten.com/1500/500',
  '//placekitten.com/4000/3000',
  '//placekitten.com/800/1200',
  '//placekitten.com/1500/1500',
];

export default class LightboxExample extends Component {
  constructor(props) {
    super(props);
    this.state = {
      photoIndex: 0,
      isOpen: false,
    };
  }

  render() {
    const { photoIndex, isOpen } = this.state;
    return (
      <div>
        <button type="button" onClick={() => this.setState({ isOpen: true })}>
          Open Lightbox
        </button>
        {isOpen && (
          <Lightbox
            mainSrc={images[photoIndex]}
            nextSrc={images[(photoIndex + 1) % images.length]}
            prevSrc={images[(photoIndex + images.length - 1) % images.length]}
            onCloseRequest={() => this.setState({ isOpen: false })}
            onMovePrevRequest={() =>
              this.setState({
                photoIndex: (photoIndex + images.length - 1) % images.length,
              })
            }
            onMoveNextRequest={() =>
              this.setState({
                photoIndex: (photoIndex + 1) % images.length,
              })
            }
          />
        )}
      </div>
    );
  }
}

其他

Keyboard shortcuts (with rate limiting) Image Zoom Flexible rendering using src values assigned on the fly Image preloading for smoother viewing Mobile friendly, with pinch to zoom and swipe (Thanks, @webcarrot!) No external CSS

部分功能需要定制

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值