我的html5画布和Kinetic.js代码不起作用

时间:2012-08-14 15:27:03

标签: javascript html5 canvas kineticjs

它有效:http://jsfiddle.net/qYYm5/

我最近从这里发现了Kinetic.js:http://www.kineticjs.com/

我试图效仿这个例子,但没有任何工作......

此代码应在“background_layer”图层上绘制图像“iPhoneBg.jpg”。不用说我的形象存在。

<!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>

这里有什么问题?

谢谢!

1 个答案:

答案 0 :(得分:1)

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>