| 开发者 |
cloudcatch
dkjensen |
|---|---|
| 更新时间 | 2026年6月25日 21:19 |
| 捐献地址: | 去捐款 |
| PHP版本: | 6.6 及以上 |
| WordPress版本: | 7.0 |
| 版权: | GPL-2.0-or-later |
| 版权网址: | 版权信息 |
/wp-content/plugins/light-modal-block directory, or install the plugin through the WordPress plugins screen directly.Each modal is given a unique ID, which can be found inside the inspector controls of the block settings. It will look something like: Mk6I8L4haJB
To open a modal:
window.lightModalBlocks.get('modal-id-here').showModal(true);
To close a modal:
window.lightModalBlocks.get('modal-id-here').closeModal();
Paste the following code in your child themes functions.php file or similar: /* * Prevents the light modal block from focusing on a specific element when it opens. * * @return void / add_action( 'wp_enqueue_scripts', function () { wp_add_inline_script( 'cloudcatch-light-modal-block-view-script', 'window.lmbFocusableElements = "";', 'before' ); } );
The class lmb-open is added to the <body> of the page when a modal is open. You can use the following CSS to prevent scrolling
.lmb-open {
overflow: hidden;
}
Add the following CSS to your child theme to fade the modal in and out: .wp-block-cloudcatch-light-modal-block__wrapper { opacity: 0; transition: opacity 0.3s ease, display 0.3s allow-discrete; } .wp-block-cloudcatch-light-modal-block__wrapper.is-open { opacity: 1; } @starting-style { .wp-block-cloudcatch-light-modal-block__wrapper.is-open { opacity: 0; } } Or, for a livelier effect, use this CSS to make the modal pop in with a springy slide and scale: .wp-block-cloudcatch-light-modal-block__wrapper { opacity: 0; transition: opacity 0.3s ease, display 0.3s allow-discrete; } .wp-block-cloudcatch-light-modal-block__wrapper.is-open { opacity: 1; } .wp-block-cloudcatch-light-modal-block__wrapper .wp-block-cloudcatch-light-modal-block { opacity: 0; transform: translateY(40px) scale(0.9); transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease; } .wp-block-cloudcatch-light-modal-block__wrapper.is-open .wp-block-cloudcatch-light-modal-block { opacity: 1; transform: translateY(0) scale(1); } @starting-style { .wp-block-cloudcatch-light-modal-block__wrapper.is-open { opacity: 0; } .wp-block-cloudcatch-light-modal-block__wrapper.is-open .wp-block-cloudcatch-light-modal-block { opacity: 0; transform: translateY(40px) scale(0.9); } }
useModals() hook via leveraging getBlocksByName().lmb-open when a modal is currently open on the page