我试图仅在悬停到特殊 div 时显示一些信息。我正在使用材质 ui 及其 withStyles 组件。有没有办法做到这一点?
问问题
234 次
1 回答
1
请检查这个例子:
import React, {useState} from "react";
export default function ShowButtonHover() {
const [style, setStyle] = useState({display: 'none'});
return (
<div className="App">
<h2>Hidden message in the box. Move mouse in the box</h2>
<div style={{border: '1px solid gray', width: 300, height: 300, padding: 10, margin: 100}}
onMouseEnter={e => {
setStyle({display: 'block'});
}}
onMouseLeave={e => {
setStyle({display: 'none'})
}}
>
<div style={style}>This was hidden</div>
</div>
</div>
);
}
于 2020-04-16T16:08:09.540 回答