简体   繁体   English

盆景JS错误

[英]Bonsai JS error

The HTML: 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>

The js (main.js): //Globals 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);

The error: 错误: 在此处输入图片说明

Any help would be greatly appreciated :) I'm not really sure what could be going wrong here. 任何帮助将不胜感激:)我不太确定这里可能出什么问题。 It looks like the docs. 看起来像文档。

You're getting this error because when you are loading the main.js file via the script tag, Rect is not defined. 之所以出现此错误,是因为通过脚本标记加载main.js文件时,未定义Rect You can delete the following line: 您可以删除以下行:

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

Alternately, you can change your use of bonsai api to code : 或者,您可以将对bonsai api的使用更改为code

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM