browserify and document ready?

后端 未结 5 1029
慢半拍i
慢半拍i 2021-02-08 00:28

I\'m struggling with using Browserify and document ready events. How do I craft a module that exports content only available after the document ready event has fired? How do I

5条回答
  •  面向向阳花
    2021-02-08 01:13

    Usually you have one master file that fires up the entire application, so you can simply wrap it in the ready callback. It doesn't make much sense to do anything before the document is ready anyway. Sure you could return a function in every single file that does DOM manipulation, but that would turn into a mess quickly.

    document.addEventListener('DOMContentLoaded', function () {
        var app = require('./app');
        // ...
    });
    

提交回复
热议问题