你好 :)我对react js比较陌生,我试图在一个div上应用动画,这个div是另一个div的子代,父div "
" 显示从wp rest api提取的特色图片,而子div "
portfolio-product-item
" 有帖子的内容。
portfolio-product-item-details
我想做的是,当悬停在父神的特色图片上时,显示内容,我的代码是这样的,我怎样才能实现它?
import React from 'react';
import Home from './Home';
require ('../../app.css');
require ('../../animate.min.css');
class Portfolio extends React.Component{
render(){
console.log(this.props.data.length);
var contents=[];
for (var i = 0; i < this.props.data.length; i++) {
contents.push(
<div className="col-xs-12 col-md-4">
<div id="portfolio-product-item" >
<img src={this.props.data[i].featured_image} />
<div ref= "productDetails" id ="portfolio-product-item-details" dangerouslySetInnerHTML={{__html: this.props.data[i].content.rendered}} />
</div>
</div>
return(
<div className = "container">
<div className="row">
<section className="portfolio">
<h1>Our Latest Work</h1>
<p id="below-header">These are some of the works that has been keeping us busy over the years. See for yourself what we can do.</p>
<div className="col-xs-12 ">
{contents}
</div>
</section>
</div>
</div>
export default Portfolio;
React允许从虚拟DOM中添加/删除元素。使用onMouseEnter和onMouseLeave来设置显示/隐藏状态。
onMouseEnter={ () => this . setState ({ show : true })} onMouseLeave={ () => this . setState ({ show : false })}然后根据状态显示/隐藏细节。
{this.state.show ? <div ref= "productDetails" id ="portfolio-product-item-details" dangerouslySetInnerHTML={{__html: this.props.data[i].content.rendered}} : null}