Use of PreloadJS


var $ = jQuery
// indicator for preloading percentage
var $indicator = $('#loadingInner')
var preload
var manifest = [
  {
    src: '/img/magic.jpg',
    id: 'magic'
  }, {
    src: '/img/snow.png',
    id: 'snow'
  }
]

// start preloading
function startPreload () {
  preload = new createjs.LoadQueue(true)
  preload.on('fileload', handleFileLoad)
  preload.on('progress', handleFileProgress)
  preload.on('complete', loadComplete)
  preload.on('error', loadError)
  preload.loadManifest(manifest)
}

// handle single file
function handleFileLoad (event) {
  console.log('File type: ' + event.item.type)
  /*
  if(event.item.id == 'magic'){
    console.log('majic picture has been loaded!');
  };
  if(event.item.id == 'photo') {
    console.log('photo picture has been loaded!')
  }
  */
}

// handle preloading error
function loadError (evt) {
  // console.log('There is something wrong!',evt.text);
}

// handle preloading process
function handleFileProgress (event) {
  var percentage = preload.progress * 100 | 0
  $indicator.css({
    width: percentage + '%'
  })
}

// handle preloading success
function loadComplete (event) {
  // console.log('All resources have been loaded!');
  setTimeout(function () {
    $('#page0').slideUp(600)
  }, 300)
  // console.log('Hello world!');
}
// invoke the method
startPreload()
Author: Yakima
关于作者:楠溪江人,出生于1991年,目前坐标上海。读书时代跳过级、保过送,工作后转过行。2013年本科毕业于北药。看书、码字、敲代码、打羽毛球是我花时间的爱好。曾在某上市药企任国际药品注册岗,现在某高新企业任前端管理岗。

2 thoughts on “Use of PreloadJS

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据