Reputation: 69
I have a lot of blocks with items. I want to show item information (block near the item), when user hover on it. Here is an example: First example Second example
Upvotes: 0
Views: 7052
Reputation: 2528
You can achieve this in react by.
class nameOfClass extends React.Component{
constructor(props){
super(props)
this.state = {
box1Hover:false,
box2Hover:false,
box3Hover:false,
box4Hover:false,
}
this.trueDisplay = this.trueDisplay.bind(this)
this.falseDisplay = this.falseDisplay.bind(this)
}
trueDisplay(e){
this.setState({[e.target.name]:true})
}
falseDisplay(e){
this.setState({[e.target.name]:false})
}
render(){
return(
<div>
<div name="box1Hover" onMouseEnter={this.trueHover} onMouseLeave={this.falseHover}>
....
// your on hover content in bellow line
{this.state.box1Hover?<h5>Mouse hovering over me</h5>:""}
....
<div>
<div name="box2Hover" onMouseEnter={this.trueHover} onMouseLeave={this.falseHover}>
....
// your on hover content in bellow line
{this.state.box2Hover?<h5>Mouse hovering over me</h5>:""}
....
<div>
<div name="box3Hover" onMouseEnter={this.trueHover} onMouseLeave={this.falseHover}>
....
// your on hover content in bellow line
{this.state.box3Hover?<h5>Mouse hovering over me</h5>:""}
....
<div>
</div>
)
}
}
if you know jquery then you can use tooltip https://www.w3schools.com/bootstrap/bootstrap_tooltip.asp
Upvotes: 2