javascript 点击图像上的React图像画廊和去全屏

qjp7pelc  于 2023-05-12  发布在  Java
关注(0)|答案(1)|浏览(95)
import "../../node_modules/react-image-gallery/styles/css/image-gallery.css";
import ImageGallery from "react-image-gallery";
import { useRef } from "react";

const images = [
  {
    original: "https://picsum.photos/id/1018/1000/600/",
    thumbnail: "https://picsum.photos/id/1018/250/150/",
  },
  {
    original: "https://picsum.photos/id/1015/1000/600/",
    thumbnail: "https://picsum.photos/id/1015/250/150/",
  },
  {
    original: "https://picsum.photos/id/1019/1000/600/",
    thumbnail: "https://picsum.photos/id/1019/250/150/",
  },
];
const Carousel = (props) => {
  const imageGalleryRef = useRef(null);

  const onClickHandler = () => {
    imageGalleryRef.current.toggleFullscreen();
  };

  return (
    <ImageGallery
      items={images}
      showThumbnails={true}
      showFullscreenButton={true}
      showPlayButton={false}
      showBullets={true}
      ref={imageGalleryRef}
      onClick={onClickHandler}
    />
  );
};

export default Carousel;

这返回imageGalleryRef.current.toggleFullscreen is not a function,但我可以从控制台运行该函数,它的工作,我做错了什么?这是实现点击图像并全屏显示的最佳方法吗?

sauutmhj

sauutmhj1#

应该是fullScreen而不是toggleFullscreen。根据功能文档:
可以使用refs访问以下函数

  • play():播放幻灯片
  • pause():暂停幻灯片
  • fullScreen():激活全屏
  • exitFullScreen():停用全屏
  • slideToIndex(index):滑动到特定索引
  • getCurrentIndex():返回当前索引

相关问题