+
80
-

grapejs如何弹出模态层窗口?

grapejs如何弹出模态层窗口?


网友回复

+
0
-

使用editor.Modal.open方法打开模态窗口图层,完整代码如下:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/grapes.0.21.1.css">
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/grapes.0.21.1.js"></script>
    <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/grapesjs-component-code-editor.min.css">
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/grapesjs-component-code-editor.min.js"></script>
    <style>
        body, html {
      margin: 0;
      height: 100%;
    }
    </style>
    <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>

</head>

<body>

    <div id="gjs">
        <h1>标题</h1>
        <img src='//repo.bfw.wiki/bfwrepo/image/5d6539613d08b.png' />
    </div>


    <script>
        const editor = grapesjs.init({
        	container: '#gjs',
   storageManager: false,


        });


// Open modal
const openModal = () => {
    editor.Modal.open({
        title: 'My title', // string | HTMLElement
        content: 'contnet', // string | HTMLElement
    });
};
// Create a simple custom button that will open the modal
document.body.insertAdjacentHTML('afterbegin',`
    <buttonBfwOnclick="openModal()">Open Modal</button>
`);

    </script>
</body>

</html>

我知道答案,我要回答