search

Home  >  Q&A  >  body text

javascript - How does js determine that all resources on the page have been loaded?

Make a progress bar and it will be 100% after loading. How to judge that the loading is complete?

天蓬老师天蓬老师2723 days ago907

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-06-12 09:31:56

    Fake loading is usually done by adding random numbers, up to 99, and after all resources are loaded, it becomes 100.

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-12 09:31:56

    Need a resource pool object

    {
        js: [a.js,b.js],
        img:[c.png, d.jpg],
        css:[e.css]
    }
    

    Preload the files, listen to the onload event, and trigger the callback
    Count the total number of files: all_files current cur_files
    Percentage: percent = all_files, cur_files.

    There is a ready-made loading library~ Go and find it on github.

    reply
    0
  • Cancelreply