如何用reactjs bootstrap实现点击全屏显示

rfbsl7qr  于 2023-03-08  发布在  React
关注(0)|答案(1)|浏览(414)

我正在使用引导样式,我想得到全屏图像时,我点击图像。
这是密码。

<Card style={{ width: '18rem' }}>
    <Card.Img variant="top" src={images} style={{marginLeft:10,marginTop:20, width: '15rem',height: '15rem' }}/>
    <Card.Body>
      <Card.Title>{name}</Card.Title>
    </Card.Body>
    <ListGroup className="list-group-flush">
      <ListGroup.Item>{number}</ListGroup.Item>
      <ListGroup.Item>{type}</ListGroup.Item>
    </ListGroup>
    <Card.Body>
      <Button variant="primary">Go somewhere</Button>
    </Card.Body>
  </Card>
bf1o4zei

bf1o4zei1#

要在用户单击图像时以全屏模式显示图像,可以使用Bootstrap Modal组件。

import { useState } from 'react';
import { Card, Button, Modal } from 'react-bootstrap';

function ImageCard({ name, number, type, image }) {
  const [showModal, setShowModal] = useState(false);

  const handleModalShow = () => setShowModal(true);
  const handleModalClose = () => setShowModal(false);

  return (
    <>
      <Card style={{ width: '18rem' }}>
        <Card.Img
          variant="top"
          src={image}
          style={{ marginLeft: 10, marginTop: 20, width: '15rem', height: '15rem' }}
          onClick={handleModalShow}
        />
        <Card.Body>
          <Card.Title>{name}</Card.Title>
        </Card.Body>
        <ListGroup className="list-group-flush">
          <ListGroup.Item>{number}</ListGroup.Item>
          <ListGroup.Item>{type}</ListGroup.Item>
        </ListGroup>
        <Card.Body>
          <Button variant="primary">Go somewhere</Button>
        </Card.Body>
      </Card>

      <Modal show={showModal} onHide={handleModalClose} size="lg">
        <Modal.Header closeButton></Modal.Header>
        <Modal.Body>
          <img src={image} alt={name} style={{ width: '100%', height: 'auto' }} />
        </Modal.Body>
      </Modal>
    </>
  );
}

相关问题