最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to hook on customizer section expandedactiveopened event?

programmeradmin2浏览0评论

I am trying to run js function when customizer section is expended and cant seem to find any event to do so.

Something like this

wp.customize.bind( 'ready', function() {

    wp.customize.section.bind( 'expand', function() {
            console.log('hello');

    }); 

} );

or

wp.customize.bind( 'ready', function() {

    wp.customize.section.on( 'opened', function() {
            console.log('hello');

    }); 

} );

or anything that triggers when section is active/activated/expanded/opened.

Any help is appreciated!

I am trying to run js function when customizer section is expended and cant seem to find any event to do so.

Something like this

wp.customize.bind( 'ready', function() {

    wp.customize.section.bind( 'expand', function() {
            console.log('hello');

    }); 

} );

or

wp.customize.bind( 'ready', function() {

    wp.customize.section.on( 'opened', function() {
            console.log('hello');

    }); 

} );

or anything that triggers when section is active/activated/expanded/opened.

Any help is appreciated!

Share Improve this question asked Oct 11, 2018 at 17:00 BennBenn 1,0431 gold badge15 silver badges32 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 3

Here it is

wp.customize.bind( 'ready', function() {

    wp.customize.section.each( function ( section ) { 

        section.expanded.bind( function( isExpanding ) {

            if(isExpanding){

                console.log(section);
            }


        });


    });
});

If you are targeting particular section, then you can do like:

wp.customize.section('title_tagline').expanded.bind(function (isExpanded) {
  if( isExpanded ) {
    // Do something here.
  }
});
发布评论

评论列表(0)

  1. 暂无评论