@cycjimmy/h5-preloader
v6.0.0
Published
Resources pre-load for h5 page
Readme
H5 Preloader
Resources pre-load for h5 page. Demo
Install
# via npm
$ npm install @cycjimmy/h5-preloader --save
# or via yarn
$ yarn add @cycjimmy/h5-preloaderModule format
Since v6 the package is ESM only:
main,moduleandexportsall point atdist/h5-preloader.esm.js.browserpoints at the UMD build,dist/h5-preloader.umd.min.js, for plain<script>tags and CDNs.- The CommonJS bundle (
dist/h5-preloader.cjs) of v5 is no longer shipped.
Node.js 20.19+ / 22.12+ can require() the ESM entry, since those versions load
an ES module synchronously. The library is browser targeted either way: it reads
window while the module is evaluated, so plain Node.js still needs a DOM (for
example jsdom) before importing it. Bundlers without exports support fall
back to the browser field and get the UMD build.
The UMD build targets ES2015, so Internet Explorer is no longer supported.
Usage
import h5Preloader from '@cycjimmy/h5-preloader'
h5Preloader({
type: 'progressBar',
progressBar: {
eProgressBar: document.querySelector('.progress-bar'),
eProgressBarPercent: document.querySelector('.text-percent'),
},
resources: [
'https://example.com/image.png',
'https://example.com/video.mp4',
],
hookWhenProgressComplete: () => {
document.querySelector('.preloader-wrapper').classList.add('hidden')
},
}).load()h5Preloaderconfig:- resources: [Require][Array] Resource paths array.
- type: [Option][String] Set type of progress. Currently only supports
'progressBar'. Default'progressBar'. - progressBar: [Option][Object] Progress bar config
- eProgressBar: [Element] Element of Progress bar.
- eProgressBarPercent: [Element] Element for showing percent.
- hookWhenProgressComplete: [Option][Function] The hook function when the progress complete.
- autoComplete: [Option][Boolean] Whether to automatic operation the hook function when the progress complete. Default
true
h5Preloaderinstance supports the following methods:load(): Start preloader.progressComplete(): Call the progress complete function manually.
CDN
To use via a CDN include this in your HTML:
<script src="https://cdn.jsdelivr.net/npm/@cycjimmy/h5-preloader@6/dist/h5-preloader.umd.min.js"></script>