首页 > 解决方案 > 如何订阅 CustomBox 模态关闭事件

问题描述

我已经实现了一个模式。我目前正在使用在此处找到的 FadeIn 模态https://htmlstream.com/preview/unify-v2.5.1/unify-main/shortcodes/shortcode-base-modals.html从查看使用此处的 CustomBox 的代码http: //dixso.github.io/custombox/

<a class="btn u-btn-primary" href="#modal1" data-modal-target="#modal1" data-modal-effect="fadein">Launch Modal
</a>

<!-- Demo modal window -->
<div id="modal1" class="text-left g-max-width-600 g-bg-white g-overflow-y-auto g-pa-20" style="display: none;">
  <button type="button" class="close" onclick="Custombox.modal.close();">
    <i class="hs-icon hs-icon-close"></i>
  </button>
  <h4 class="g-mb-20">Modal title</h4>
  <p>Modal Body</p>
</div>
<!-- End Demo modal window -->

我可以看到 CustomBox 的事件类型为 Closed,但我不确定如何正确订阅该事件。我添加了以下代码,但没有任何反应。模态关闭后。

document.addEventListener('custombox.close', function() {

});

请问如何正确订阅CustomBox的关闭事件?

标签: javascripthtml

解决方案


我不熟悉您正在使用的库,但您可以将 JavaScript 函数调用添加到onclick关闭按钮中定义的

<button type="button" class="close" onclick="Custombox.modal.close(); someCloseCallback();">

推荐阅读