react 鼠标放上去显示更多文字的卡片

jsx代码
import React from 'react';
import styles from './MyCard.less';

export default class MyCard extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hover: false };
  }

  handleMouseEnter = () => {
    this.setState({
      hover: true,
    });
  };

  handleMouseLeave = () => {
    this.setState({
      hover: false,
    });
  };

  render() {
    const { hover } = this.state;
    const cardTop = hover ? { height: '100px', opacity: 1 } : { height: '450px', opacity: 1 };
    const cardBottom = hover
      ? { height: '350px', opacity: 1 }
      : { height: '0px', opacity: 1, display: 'none' };
    return (
      <div
        onMouseEnter={this.handleMouseEnter.bind(this)}
        onMouseLeave={this.handleMouseLeave.bind(this)}
      >
        <div className={styles.card}>
          <div className={styles.cardTop} style={cardTop} />
          <div className={styles.cardTitle}>
            <h1>游褒禅山记</h1>
          </div>
          <div className={styles.cardBottom} style={cardBottom}>
            而世之奇伟、瑰怪、非常之观,常在于险远,而人之所罕至焉,故非有志者不能至也。尽吾志也而不能至者,可以无悔矣,其孰能讥之乎?
          </div>
        </div>
      </div>
    );
  }
}

less 样式

.card {
  margin: auto;
  position: relative;
  display: block;
  background: #e61620;
  width: 200px;
  height: 500px;
  background-image: url('https://os.alipayobjects.com/rmsportal/QBnOOoLaAfKPirc.png');
  background-size: contain;
}
.cardTop {
  bottom: 0;
  background: transparent;
  width: 200px;
  padding: 30px;
  height: 400px;
}
.cardTitle {
  bottom: 0;
  background: #b6b919;
  width: 200px;
  padding: 30px;
  height: 50px;
  z-index: 1;
}
.cardBottom {
  bottom: 0;
  background: #19b93c;
  width: 200px;
  padding: 30px;
  height: 0px;
}

实现效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

liuyunshengsir

微信:lys20191020

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值