【问题标题】:react photoswipe gallery of thumbnails will not display as gridreact photoswipe 缩略图库将不会显示为网格
【发布时间】:2021-10-20 22:56:17
【问题描述】:

我正在使用照片滑动图库。

这样做时,我会将所有缩略图放在一行中...我希望它们像网格一样填充页面。

下面是我的反应组件代码。我注意到,如果我在 dev tools->inspect 中查看每个缩略图并将显示更改为“inline”,我不会在每个缩略图之后/之前出现换行符。它仍然看起来很垃圾,因为缺少框架和其他东西,但是,我不知道如何或在哪里修改缩略图的外观或样式将其放入我的代码中。

从“react-photoswipe-2”导入 { PhotoSwipeGallery };

const useStyles = makeStyles((theme) => ({
    loadingPaper: {
        margin: "auto",
        width: '50%',
        padding: '10px',
        marginTop: "50px"
    }
}));


function FrameViewer(props) {
    const classes = useStyles();
    let { cameraAccessor } = useParams();
    const [frames, setFrames] = useState([]);
    const [isGalleryOpen, setIsGalleryOpen] = useState(false);
    const [imgGalleryH, setGalleryImgH] = useState(0);
    const [imgGalleryW, setGalleryImgW] = useState(0);
    const [cameraID, setCameraID] = useState("");
    const { cameras } = props;


    async function fetchCameraData(cameraAccessor) { // TODO: check if already loading before running.  // code to get filenames and what not
    }

    useEffect(() => {
// code to lead camera data
    }, [cameraAccessor]);

    const getThumbnailContent = item => (
        <img src={item.thumbnail} width={120} height={90} alt="" />
    );

    let cam = cameras[cameraID];

    if (cam) { // Photoswipe requires a Height and Width ... so we need to load the first image and see how big before we can incept Photoswipe.

        var img = new Image();
        img.onload = function () {
            setGalleryImgH(img.height);
            setGalleryImgW(img.width);
        }
        img.src = "https://apps.usgs.gov/sstl/media/cameras/" + cameraFolderName(cam) + "/" + cameraFolderName(cam) + MOST_RECENT_FRAME_SUFFIX;
    }



    return (
        <React.Fragment>
            {cam && frames && frames.length && imgGalleryH > 0 && imgGalleryW > 0
                ? <PhotoSwipeGallery

                    items={frames.map((filename) => {
                        return {
                            src: 'https://example.com/media/cameras/' + cameraFolderName(cam) + '/' + filename,
                            thumbnail: 'https://example.com/media/cameras/' + cameraFolderName(cam) + '/' + filename,
                            w: imgGalleryW,
                            h: imgGalleryH,
                            title: filename.replace("_overlay.jpg", "").split("___")[1].replace("_", " ")
                        }
                    })}
                    options={{
                        closeOnScroll: false
                    }}
                    thumbnailContent={getThumbnailContent}
                    isOpen={isGalleryOpen}
                    onClose={() => setIsGalleryOpen(false)}
                />
                : <Paper elevation={5} className={classes.loadingPaper}><Typography color="textSecondary" align='center'>loading...</Typography></Paper>
            }
        </React.Fragment >
    );
}

【问题讨论】:

    标签: css reactjs photoswipe


    【解决方案1】:

    编辑您的 CSS。尝试在容器级别(.pswp-thumbnails)覆盖 display 属性:

    .pswp-thumbnails
    {
      display: flex;
    }
    

    ...OR 在缩略图级别 (.pswp-thumbnail):

    .pswp-thumbnail {
      display: inline-block;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-08-20
      • 2011-05-07
      • 1970-01-01
      • 2014-10-02
      • 2012-04-18
      • 2022-11-13
      • 2019-07-11
      • 2014-08-29
      • 1970-01-01
      相关资源
      最近更新 更多