我有一个动态呈现的标题列表,当我将鼠标悬停在每个标题上时,我想显示一个图像。当我悬停标题时,会显示所有图像。我仍然是 React 的新手。我认为解决方案很简单,但我没有找到。
Component.js
import React, { useEffect, useRef } from "react";
import { Row, Col } from "react-bootstrap"
import Link from "next/link";
import gsap from "gsap";
import { getStrapiMedia } from "../lib/media";
const Articles = ({ articles }) => {
const itemsRef = useRef({});
const handleHover = (e) => {
gsap.to(".imgHome", {
display: "block"
})
}
const handleHoverExit = (e) => {
gsap.to(".imgHome", {
display: "none"
})
}
return (
<div>
<div className="tableau">
{articles.map((item) => (
<Row key={item.id}
onMouseEnter={(e) => handleHover(e)}
onMouseOut={(e) => handleHoverExit(e)}
ref={el => (itemsRef.current[item.id] = el)}>
<Link href={`/article/${item.id}`}>
<a className="titre"
>{item.title} </a>
</Link>
<img className="imgHome" src={getStrapiMedia(item.image.url)}
width="800" />
</Row>
))}
</div>
</div>
)
}
export default Articles