盆景JS错误

时间:2017-01-08 04:32:20

标签: javascript bonsaijs

HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!-- <script src="bonsai.js" type="text/javascript"></script> -->
    <script src="http://cloud.github.com/downloads/uxebu/bonsai/bonsai-0.4.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
    <script src="main.js" type="text/javascript"></script>
    <title> Testing </title>
  </head>

  <body>
    <div id="test"></div>
    <script>
      bonsai.run(document.getElementById('test'),{
        url: 'main.js',
        width: 1260,
        height: 680
      });
    </script>
  </body>
</html>

js(main.js): //全局

var screenWidth = 1260;
var screenHeight = 680;

var background = new Rect(0, 0, screenWidth, screenHeight).fill('#d3d3d3').addTo(stage);

window.setInterval(function(){
  console.log('hi');
}, 100);

错误: enter image description here

任何帮助都会非常感激:)我不确定这里会出现什么问题。它看起来像文档。

1 个答案:

答案 0 :(得分:1)

您收到此错误的原因是,当您通过脚本标记加载main.js文件时,未定义Rect。您可以删除以下行:

<script src="main.js" type="text/javascript"></script>

或者,您可以将盆景api的使用更改为code

bonsai.run(document.getElementById('test'),{
  code: function () {
   //your code inside main.js
  },
  width: 1260,
  height: 680
});