This is a preloader, it scans DOM and loaded StyleSheet’s for occurence of images (in sheet, style, as element).
StyleSheet file has to be in the same domain as page using it.

Each callback function’s ‘this’ object has three attributes: loaded, count, timeout.



  • PfeLoader.start({onStart=null, onChange=null, onStop=null, imgs=[], timeout=0, findImages=true});
    • will start preloading of images
    • onStart, onChange, onStop are functions which will be ran on event occurence.
    • imgs is an array of img srcs
    • timeout is a timeout after which script will stop wait for an image,
      setting it to 0 (default) results in no timeout.
    • findImages whatever scan for images in DOM is needed
  • PfeLoader.demo({onStart=null, onChange=null, onStop=null, imgs=[], timeout=0, findImages=true});
    • arguments are the same as in start(),
      this method can be used to test our callbacks. It searches for images and gets it count, next it increments counters and runs callbacks when applicable.


document.title=this.loaded + "/" + this.timeout + " : "+ this.count +
" (" + (parseInt((this.loaded+this.timeout)/this.count*100)) + ")";

Leave a comment