Random78952
Random78952

Reputation: 1640

My html5 canvas and Kinetic.js code is not working

It's worked : http://jsfiddle.net/qYYm5/

I recently discovered Kinetic.js from here : http://www.kineticjs.com/

I tried to follow that example, but nothing is working...

This code should draw an image "iPhoneBg.jpg" on the layer "background_layer". Needless to say my image exists.

<!DOCTYPE HTML>
<html>
  <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
    <script src="Kinetic.min.js"></script>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
    <script>
        window.onload = function() {
            //INITIALISATION
            var stage = new Kinetic.Stage({
                container: "iPhone",
                width: 480,
                height: 720
            });
            //LAYERS
            var background_layer = new Kinetic.Layer();
            var sms_layer = new Kinetic.Layer();
            var text_layer = new Kinetic.Layer();
            //ELEMENTS
            var iPhoneBg_image = new Kinetic.Image({
                image: 'iPhoneBg.jpg'
            });
            //DRAWING
            background_layer.add(iPhoneBg_image);
            stage.add(background_layer);
        };

    </script>
  </head>
  <body>
    <canvas id="iPhone" width="480" height="720"></canvas>
  </body>
</html>

What is the problem here?

Thanks!

Upvotes: 2

Views: 3514

Answers (1)

Palani Kumar
Palani Kumar

Reputation: 1137

window.onload = function() { //INITIALISATION var stage = new Kinetic.Stage({ container: "iPhone", width: 480, height: 720 }); //LAYERS var background_layer = new Kinetic.Layer(); var sms_layer = new Kinetic.Layer(); var text_layer = new Kinetic.Layer(); //ELEMENTS var imageObj = new Image(); imageObj.onload = function() { var iPhoneBg_image = new Kinetic.Image({ image: imageObj }); //DRAWING background_layer.add(iPhoneBg_image); stage.add(background_layer); } imageObj.src = "iPhoneBg.jpg"; }; <body><div id="iPhone"></div></body>

Upvotes: 1

Related Questions