1 回答
TA贡献1820条经验 获得超2个赞
在我在这里对您的代码进行的测试中,我添加了showPlayOnHover属性以将其声明为 false,以处理悬停时出现的按钮。
添加了渲染或不渲染按钮的方法:
handlePlayOnHover = (song) => {
this.setState({
showPlayOnHover: !this.state.showPlayOnHover,
isPlaying: !this.state.isPlaying
})
this.handleSongClick(song)
}
歌曲渲染结构更新为:
<tr
className="song" key={index}
onClick={() => this.handleSongClick(song)}
onMouseOver={() => this.handleOnHover(song)}
onMouseOut={() => this.handleOnHover(song)}
>
<td className="song-actions">
<button>
<span className="song-number">
{!this.state.showPlayOnHover ? index+1 : <span className="ion-play"></span>}
</span>
<span className="ion-play"></span>
<span className="ion-pause"></span>
</button>
</td>
<td className="song-title">{song.title}</td>
<td className="song-duration">{song.duration}</td>
</tr>
方法handleOnHover负责有条件地显示悬停时的播放按钮和悬停时的歌曲编号。
添加回答
举报