0

I am trying to load the script before the layout page load, please check my scenario in my attached video,

https://share.getcloudapp.com/p9uAR4JX

jQuery(window).load(function() {

    jQuery('div.custom-metabox').hide();

    setTimeout(function(){
        jQuery('div.custom-metabox').fadeIn('slow');
    },1000);
    
    });

but the layout is loading before the page. how should I prevent this, I have enqueued the script like this,

 wp_enqueue_script( 'custom', include_plugin_url( 'assets/js/custom.js' ), array(), $version, false );

any help will be appreciated

Nayeem Hyder Riddhi
  • 495
  • 1
  • 5
  • 18

1 Answers1

3

You can hide div.custom-metabox by css:

div.custom-metabox{display:none;}

Register the script in footer and tells the dependancy:

wp_enqueue_script( 'custom', include_plugin_url( 'assets/js/custom.js' ), array('jquery'), $version, true);

Then you can just fade in this section after 1Sec:

jQuery(document).ready(function() {

    setTimeout(function(){
        jQuery('div.custom-metabox').fadeIn('slow');
    },1000);
    
});