Shi*_*iGi 5 javascript css modalpopupextender popup reactjs
我在 React 中有一个 Image 类,并且有一个按钮应该在每个图像上实现单击扩展。我决定使用模态弹出窗口,因此当我单击时,图像将在模态弹出窗口中显示更大。我发现很难将模态设置为图像。
先感谢您。
这是来自ImageReact 中的类:
<FontAwesome
className="image-icon"
name="expand"
title="expand"
onClick={this.showModal}
/>
<Modal show={this.state.isExpand} handleClose={this.hideModal} />
Run Code Online (Sandbox Code Playgroud)
模态:
const Modal = ({ handleClose, show }) => {
const showHideClassName = show ? 'modal display-block' : 'modal display-none';
return (
<div className={showHideClassName}>
<section className="modal-main">
<button onClick={handleClose}>close</button>
</section>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
尝试这个示例代码。这是示例 ImageComponent 的链接https://codesandbox.io/s/4xnxqz0ylx
export default class ImageComponent extends React.Component {
state = { isOpen: false };
handleShowDialog = () => {
this.setState({ isOpen: !this.state.isOpen });
console.log('cliked');
};
render() {
return (
<div>
<img
className="small"
src="/Anj.png"
onClick={this.handleShowDialog}
alt="no image"
/>
{this.state.isOpen && (
<dialog
className="dialog"
style={{ position: 'absolute' }}
open
onClick={this.handleShowDialog}
>
<img
className="image"
src="/Anj.png"
onClick={this.handleShowDialog}
alt="no image"
/>
</dialog>
)}
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41371 次 |
| 最近记录: |