WordPress Customizer:选择性刷新完成后触发JS

问题描述

当特定设置更改时,我尝试在“定制程序预览”中执行一些JS。 就我而言,我需要在选择性刷新完成后获取标头的高度。

我通过以下方式尝试过:

*--------------------------------------------------------------
# Selective Refresh
--------------------------------------------------------------*/
/**
 * Custom JavaScript functions for the customizer preview after selective refresh
 *
 * @version 1.0.0
 */
;(function () {
    document.addEventListener('DOMContentLoaded',function () {
        /**
         * Selectice refresh check from https://github.com/xwp/wp-jetpack/blob/feature/selective-refresh-widget-support/modules/widgets/contact-info/contact-info-map.js#L35
         * @type {*}
         */
        
        hasSelectiveRefresh = (
            'undefined' !== typeof wp &&
            wp.customize &&
            wp.customize.selectiveRefresh &&
            wp.customize.widgetsPreview &&
            wp.customize.widgetsPreview.WidgetPartial
        );
        if (hasSelectiveRefresh) {
            wp.customize.selectiveRefresh.bind('partial-content-rendered',function (placement) {


                // Header
                wp.customize( 'hm_style_setting',function( setting ) {
                    var newHeaderStyle = setting.get();

                    if ( 'logo-top-nav' === newHeaderStyle ) {
                        var headerHeight   = $('#masthead).height();
                        
                        console.log(headerHeight);
        
                    }

                });


            });
        }
    });

})();

我的问题是在事件DOMContentLoaded上没有其他资源被加载。 为了获得正确的标题高度,必须加载徽标,但此时还没有。

有人知道如何解决此问题吗?

非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)