我使用的材料用户界面,并希望放大卡,当你悬停在它完全如图所示here
我该怎么做呢?我用过raised属性,但不是我想要的,我甚至看到有人用zDepth,但也不行。我的文件是这样的:
import React, { useState } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Card from '@material-ui/core/Card';
import CardActionArea from '@material-ui/core/CardActionArea';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import theme from '../theme';
const useStyles = makeStyles({
root: {
maxWidth: 310,
margin: theme.spacing(5),
},
});
export default function ImgMediaCard(props) {
const classes = useStyles();
const [state, setState] = useState({
raised:false,
shadow:1,
})
return (
<Card className={classes.root}
onMouseOver={()=>setState({ raised: true, shadow:3})}
onMouseOut={()=>setState({ raised:false, shadow:1 })}
raised={state.raised} zDepth={state.shadow}>
<CardActionArea>
<CardMedia
component="img"
alt={props.alt}
height="140"
image={props.img}
title={props.title}
/>
<CardContent>
<Typography gutterBottom variant="h5" component="h2">
{props.caption}
</Typography>
<Typography variant="body2" color="textSecondary" component="p">
{props.description}
</Typography>
</CardContent>
</CardActionArea>
<CardActions>
<Button size="small" color="primary">
Share
</Button>
<Button size="small" color="primary">
Learn More
</Button>
</CardActions>
</Card>
);
}
3条答案
按热度按时间ifsvaxew1#
看起来那个网站上的实现在卡片上使用了
transform: scale3d
on-hover,所以你可以去做同样的事情,因为你正在复制行为。我利用了你已经拥有的raise
状态,而不是伪类:hover
。请参阅下面的代码:7d7tgy0s2#
这可以很容易地通过使用“&”来定义悬停样式来实现。在Card的根样式中使用
"&:hover"
。iqjalb3h3#
以下是@Saud00的答案,这是MUI v5方法: