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 (
      

游褒禅山记

而世之奇伟、瑰怪、非常之观,常在于险远,而人之所罕至焉,故非有志者不能至也。尽吾志也而不能至者,可以无悔矣,其孰能讥之乎?
); } }

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;
}

实现效果

react 鼠标放上去显示更多文字的卡片_第1张图片

你可能感兴趣的:(react,前端)