在线效果浏览:
需求:mouseover图片时,透明度为100(即不透明,完全显示),mouseout,图片透明度减为30
解析:动态添加/移除类 current,用来修改其实opacity值
import React,{useState} from 'react'; import ReactDOM from 'react-dom'; import './index.css'; function Changetransparent(props){ const [lists,setLists]=useState(props.lists); const handleOver=function(list,index){ var newList=[...lists]; newList[index].isActive=true; setLists(newList); } const handleOut=function(list,index){ var newList=[...lists]; newList[index].isActive=false; setLists(newList); } const imgLists=lists.map((list,index)=> <li key={list.src} onMouseOver={()=>handleOver(list,index)} onMouseOut={()=>handleOut(list,index)} className={list.isActive ? 'current' : ''} > ) return(
-
{imgLists}