【问题标题】:React Image Magnifiers not working when zoom in using nextjs使用 nextjs 放大时 React Image Magnifiers 不起作用
【发布时间】:2020-09-18 12:00:26
【问题描述】:

我想在悬停时放大图像并使用此插件react-image-magnifiers 通常在没有next.js 的情况下会很好,但是当我使用next.js 时仅显示图像并且当我尝试将鼠标悬停在图像上时,然后放大不行,可能我的next.config.js有什么错误?

这是我的next.config.js

const withPlugins = require('next-compose-plugins');
const withCss = require('@zeit/next-css');
const withSass = require('@zeit/next-sass');
const withImages = require('next-images');

const nextSettings = {
    exportTrailingSlash: true,
    exportPathMap: function() {
        return {
            '/': { page: '/' },
        };
    },
};

module.exports = withPlugins([[withSass(withCss({
    webpack: function (config) {
        config.module.rules.push({
            test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 100000,
                    name: '[name].[ext]'
                }
            }
        })
        return config
    }
})), withImages()]]);

这是我的 Gallery.jsx

import React from "react";
import Slider from "react-slick";
import "slick-carousel/slick/slick.css"; 
import "slick-carousel/slick/slick-theme.css";
import { SideBySideMagnifier } from "react-image-magnifiers";

export default function GallerySide (props) {
    const dataImage = props.product;

    const [state, setState] = React.useState({
        alwaysInPlace: false,
        overlayOpacity: 0.6,
        switchSides: false,
        fillAvailableSpace: false,
        fillAlignTop: false,
        fillGapLeft: 0,
        fillGapRight: 10,
        fillGapTop: 10,
        fillGapBottom: 10,
        largeImage: dataImage[0].largeImage,
    });

    const {
        alwaysInPlace,
        overlayOpacity,
        switchSides,
        fillAvailableSpace,
        fillAlignTop,
        fillGapLeft,
        fillGapRight,
        fillGapTop,
        fillGapBottom,
        largeImage
    } = state;

    const ArrowLeft = (props) => (
        <a href="#disabled" {...props} className="grist-prev">
            <i className="fas fa-chevron-left"></i>
        </a>
    );

    const ArrowRight = (props) => (
        <a href="#disabled" {...props} className="grist-next">
            <i className="fas fa-chevron-right"></i>
        </a>
    );

    const settings = {
        dots: false,
        infinite: true,
        speed: 500,
        slidesToShow: 4,
        slidesToScroll: 1,
        prevArrow: <ArrowLeft />,
        nextArrow: <ArrowRight />,
    };

    const ChangeSlider = (event) => {
        setState({ 
            alwaysInPlace: false,
            overlayOpacity: 0.6,
            switchSides: false,
            fillAvailableSpace: false,
            fillAlignTop: false,
            fillGapLeft: 0,
            fillGapRight: 10,
            fillGapTop: 10,
            fillGapBottom: 10,
            largeImage: event,
        });
    }

    return (
        <>
            <SideBySideMagnifier
                className="grist-input-position"
                style={{ order: switchSides ? "1" : "0" }}
                imageSrc={largeImage}
                largeImageSrc={largeImage}
                alwaysInPlace={alwaysInPlace}
                overlayOpacity={overlayOpacity}
                switchSides={switchSides}
                zoomPosition="left"
                inPlaceMinBreakpoint={641}
                fillAvailableSpace={fillAvailableSpace}
                fillAlignTop={fillAlignTop}
                fillGapTop={fillGapTop}
                fillGapRight={fillGapRight}
                fillGapBottom={fillGapBottom}
                fillGapLeft={fillGapLeft}
                zoomContainerBorder="1px solid #ccc"
                cursorStyle="zoom-in"
            />
            
            <div className="col-12 mt-2">
                <div className="col-11 mx-auto">
                    <Slider {...settings}>
                        {dataImage.map((data, index) => 
                            <a href="#disabled" key={index} onClick={() => ChangeSlider(data.largeImage)}>
                                <div className="card m-2">
                                    <div className="card-body p-0">
                                        <img src={data.thumbImage} width="100%" alt="Grist" />
                                    </div>
                                </div>
                            </a>
                        )}
                    </Slider>
                </div>
            </div>
        </>
    );
}

我希望有这样的解决方案或其他方式来制作这样的东西。

更新:

我解决了这个问题,因为我有 scss 调用“typhography.scss”并使标签“img”最大宽度:100%,因为我的图像总是设置 100% 的宽度,禁用或删除此行

img {
     max-width: 100%;
}

效果很好,谢谢。

【问题讨论】:

  • 嗨伊万朱利安。请不要在问题中添加“(已解决)”和答案。相反,写作为答案。
  • 对不起,我已被删除“(已解决)”
  • Ivan Juliant 还将您的解决方案写为答案,而不是在问题中

标签: javascript reactjs next.js


【解决方案1】:

我解决了这个问题,因为我有 scss 调用“typhography.scss”并使标签“img”最大宽度:100%,因为我的图像总是设置 100% 的宽度,禁用或删除此行

img {
     max-width: 100%;
}

效果很好。

【讨论】:

  • 感谢@Ivan Juliant。它节省了我很多时间:-)
  • 谢谢,也帮助了我! (在我的例子中,它是 Bootstrap 的默认样式)
【解决方案2】:

正确答案是标记为正确的答案。

要以一般方式禁用,请使用以下 css 规则:

img {
    max-width: unset !important;
}

【讨论】:

    猜你喜欢
    • 2017-08-20
    • 2021-05-25
    • 2018-09-13
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多