Skip to content
This repository
tree: 6c9e833c12
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 207 lines (162 sloc) 6.261 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
<!DOCTYPE html>
<html>
<head>
    <title>Preload Images example</title>

    <script src="http://code.createjs.com/easeljs-0.4.2.min.js"></script>
    <script src="http://code.createjs.com/tweenjs-0.2.0.min.js"></script>

<script type="text/javascript" src="../src/preloadjs/AbstractLoader.js"></script>
<script type="text/javascript" src="../src/preloadjs/PreloadJS.js"></script>
<script type="text/javascript" src="../src/preloadjs/TagLoader.js"></script>
<script type="text/javascript" src="../src/preloadjs/XHRLoader.js"></script>

<!-- We also provide hosted minified versions of all CreateJS libraries.
http://code.createjs.com -->

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

    <script type="text/javascript">

        var loaderBar;
        var stage;
        var loaderStage;
        var bar;
        var lc;
        var offset;
        var imageContainer;
        var currentImage;
        var update;
        var borderPadding;
        var loaderWidth;
        var loaderColor;
        var totalLoaded;
        var preload;

        function init() {
         if (window.top != window) {
         document.getElementById("header").style.display = "none";
         }

manifest = [
{src:"./assets/image0.jpg", id:"image0"},
{src:"./assets/image1.jpg", id:"image1"},
{src:"./assets/image2.jpg", id:"image2"},
{src:"./assets/image3.jpg", id:"image3"}
];

            canvas = document.getElementById('myCanvas');
            lc = document.getElementById('loaderCanvas');
            update = false;
            stage = new Stage(canvas);
            loaderStage = new Stage(lc);
            totalLoaded = 0;
            borderPadding = 10;

            var barHeight = 20;
            loaderColor = Graphics.getRGB(0,0,0)
            loaderBar = new Container();

            bar = new Shape();
            bar.graphics.beginFill(loaderColor);
            bar.graphics.drawRect(0, 0, 1, barHeight);
            bar.graphics.endFill();

            imageContainer = new Container();
            imageContainer.x = 430;
            imageContainer.y = 200;
            loaderWidth = 800;
            stage.addChild(imageContainer);

            var bgBar = new Shape();
            var padding = 3
            bgBar.graphics.setStrokeStyle(1);
            bgBar.graphics.beginStroke(loaderColor);
            bgBar.graphics.drawRect(-padding/2, -padding/2, loaderWidth, barHeight+padding);

            loaderBar.addChild(bgBar);
            loaderBar.addChild(bar);
            loaderBar.x = loaderBar.y = 10;

            loaderStage.addChild(loaderBar);

            preload = new PreloadJS();
            preload.onProgress = handleProgress;
            preload.onComplete = handleComplete;
            preload.onFileLoad = handleFileLoad;
            preload.loadManifest(manifest);

            loaderStage.update();
            stage.update();
            Ticker.setFPS(30);
            Ticker.addListener(window);
        }

        function stop() {
Ticker.removeListener(window);
if (preload != null) { preload.close(); }
        }

        function handleProgress(event) {
            bar.scaleX = (event*100)*(loaderWidth/100);
            loaderStage.update();
            if (bar.scaleX >= (100*(loaderWidth/100))) {
                loaderBar.visible = false;
                loaderStage.update();
            }
        }

        function handleFileLoad(event) {
            var img = new Image();
            img.src = event.src;
            img.onload = handleLoadComplete;
        }

        function handleLoadComplete(event) {

            var movieClip = new Container();
            var bmp = new Bitmap(this);
            var _w = this.width;
            var _h = this.height;

            bmp.scaleX = bmp.scaleY = .75;
            bmp.regX = _w/2;
            bmp.regY = _h/2;
            bmp.onPress = handlePress;
            bmp.rotation = Math.random() * 16 - 8;

            var border = new Shape();
            border.graphics.beginFill(Graphics.getRGB(255,255,255));
            border.graphics.drawRect(0, 0, _w+borderPadding, _h+borderPadding);
            border.graphics.endFill();
            border.rotation = bmp.rotation;
            border.regX = _w/2;
            border.regY = _h/2;
            bmp.x = bmp.y = (borderPadding/2) * bmp.scaleX;

            border.scaleX = border.scaleY = bmp.scaleX;

            border.shadow = new Shadow('#000000', 0, 0, 2.5);

            movieClip.addChild(border);
            movieClip.addChild(bmp);

            imageContainer.addChild(movieClip);
            update = true;
            totalLoaded += 1;

            if (totalLoaded == manifest.length) {
                update = false;
                stage.update();
            }
        }

        function tweenComplete1() {

        }

        function handlePress(event) {
            currentItem = event.target.parent;
            update = true;
            var tween = Tween.get(currentItem).to({y:-350}, 200).call(tweenComplete);
        }

        function tweenComplete() {
            imageContainer.addChildAt(currentItem, 0);
            var tween = Tween.get(currentItem).to({y:0}, 500).call(tweenComplete2);

        }

        function tweenComplete2() {

            stage.update();
            update = false;
        }

        function handleMove(event) {
            currentItem.x = event.stageX+offset.x;
            currentItem.y = event.stageY+offset.y;
            stage.update();
        }

        function handleComplete(event) {
            //console.log('handleComplete', event, totalLoaded);


        }

        function tick() {
            if (update) {
                stage.update();
            }
        }

    </script>
<link rel="stylesheet" href="./assets/demoStyles.css" />
</head>
<body onload="init()">

<header id="header" class="PreloadJS">
<h1><span class="text-product">Preload<strong>JS</strong></span> Image Gallery</h1>
<p>This sample loads a number of images, and adds them to a canvas stage when they are complete. Click the image to view the next one.</p>
</header>

    <canvas id="myCanvas" width="960" height="400"></canvas><br/>
</body>
</html>
Something went wrong with that request. Please try again.