reactjs 在react-material-ui-carousel中隐藏导航按钮

0s7z1bwu  于 2023-06-05  发布在  React
关注(0)|答案(2)|浏览(143)

我刚刚实现了react material ui carousel,它非常简单,唯一我没有理解的是如何隐藏按钮并只在上面显示它们。我注意到 prop navButtonsAlwaysVisible并将其设置为false,但这还不够。我应该实现我自己的逻辑,或者我只是错过了什么?
下面是组件代码:

import styles from '../../styles/Testimonial.module.scss'
import Image from 'next/image'
import Carousel from 'react-material-ui-carousel'

const Testimonial = _ => {
const items = [
        {
            imageUrl: "/png/image0.webp",
            feedback: "feedback0",
            name: "name0",
            location: "location0"
        },
        {
            imageUrl: "/png/image1.jpeg",
            feedback: "feedback1",
            name: "name1",
            location: "location1"
        }
    ]

    return (
        <div id="customers" className={`section ${styles.testimonial}`}>
            <h2 className={`title ${styles.title}`}>Clientes Felizes</h2>
            <span className={"separator"}> </span>

            <Carousel
                className={styles.carousel}
                autoPlay={true}
                stopAutoPlayOnHover={true}
                interval={5000}
                animation={"slide"}
                swipe={true}
                navButtonsAlwaysVisible={false}
                navButtonsProps={{ 
                    style: {
                        backgroundColor: "#8f34eb",
                        opacity: 0.4
                    }
                }} 
            >
                {
                    items.map( (item, i) => <Item key={i} item={item} /> )
                }
            </Carousel>
        </div>
    )
}

function Item(props)
{
    return (
        <article className={styles.testimonial__card}>
            <div className={styles.testimonial__photo_container}>
                <Image
                    className={styles.testimonial__photo}
                    src={props.item.imageUrl}
                    alt="Testimonial"
                    width={312}
                    height={300}
                />
            </div>
            <p className={styles.testimonial__copy}>{props.item.feedback}</p>
            <span className={styles.testimonial__name}>{props.item.name}</span>
            <span className={styles.testimonial__city}>{props.item.location}</span>
        </article>
    )
}

export default Testimonial;
qv7cva1a

qv7cva1a1#

有一个名为 navButtonsAlwaysInvisible 的 prop

navButtonsAlwaysInvisible={true}
ovfsdjhp

ovfsdjhp2#

您可以尝试使用自定义CSS为您的目的。基于当前呈现的标记,

.jss6 {
    opacity: 0;
    transition: all ease 1000ms; /* So that it does not disappear quickly */
}

您可以定义父容器的悬停,使其仅在父容器悬停时显示:

.jss1.Testimonial_carousel__3rny3:hover .jss6 {
    opacity: 1;
}

这就是它现在的工作方式:

相关问题