Last active
December 14, 2015 13:09
-
-
Save nakajmg/5091385 to your computer and use it in GitHub Desktop.
PreloadJSで画像を読み込むたびにDOMに追加していくコード。PreloadJS用のeventが用意されているのでそれぞれのeventに対してhandlerを割り当てる。 http://www.createjs.com/Docs/PreloadJS/modules/PreloadJS.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>PreloadJS</title> | |
</head> | |
<body> | |
<h2>PreloadJS!!</h2> | |
<h3 id="state"></h3> | |
<div id="images"></div> | |
<script src="./preloadjs-0.3.0.min.js"></script> | |
<script> | |
function init(){ | |
var manifest = [ | |
{src: "d.png", id:"file1"}, | |
{src: "vs.gif", id:"file2"}, | |
{src: "go.png", id:"file3"} | |
]; | |
var loader = new createjs.LoadQueue(false); | |
loader.addEventListener('fileload',handleFileLoad); | |
loader.addEventListener('complete',handleComplete); | |
loader.addEventListener('progress',handleProgress); | |
loader.loadManifest(manifest,false); | |
loader.load(); | |
function handleFileLoad(event){ | |
var image = event.result; | |
var item = event.item; | |
console.log("type:"+item.type + " ext:"+item.ext); | |
document.getElementById('images').appendChild(image); | |
} | |
function handleProgress(){ | |
document.getElementById('state').innerText = "loading..."; | |
} | |
function handleComplete(){ | |
document.getElementById('state').innerText = "complete!!"; | |
// var mleng = manifest.length; | |
// for(var i = 0; i < mleng; i++){ | |
// var id = manifest[i].id; | |
// var file = loader.getResult(id); | |
// document.getElementById('images').appendChild(file); | |
//} | |
} | |
window.onload = function(){ | |
init(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment