[英]Kinetic JS not working from external script file?
So I want manipulate canvas, but Kinetic JS doesn't seem to work, don't know why. 所以我想操纵画布,但Kinetic JS似乎不起作用,不知道为什么。
This code is from a tutorial: 这段代码来自一个教程:
$(function(){
var stage = new Kinetic.Stage({
container: 'gridalea',
width: 172,
height: 720
});
var layer = new Kinetic.Layer();
var rect = new Kinetic.Rect({
x: 239,
y: 75,
width: 100,
height: 50,
fill: 'green',
stroke: 'black',
strokeWidth: 4
});
// add the shape to the layer
layer.add(rect);
// add the layer to the stage
stage.add(layer);
});
this is in a tone.js file inside a js folder. 这是在js文件夹中的tone.js文件中。
here is my html head: 这是我的html头:
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery.transit.min.js"></script>
<script src="js/kinetic-v4.7.4.min.js"></script>
<script src="js/tone.js"></script>
and the canvas inside the body, the child of some divs. 和身体内的画布,一些div的孩子。
<canvas id="gridalea" width="175px" height="720px">Your browser does not support canvas.</canvas>
I don't see what is wrong with it. 我没有看到它有什么问题。 I have all the files correctly where they should be, no errors in Firebug. 我有正确的所有文件,Firebug中没有错误。 Can you help me somehow? 你能以某种方式帮助我吗?
EDIT: I tried to get the values of variables in Firebug, they are not defined. 编辑:我试图在Firebug中获取变量的值,它们没有定义。
it looks like they used a div as the container rather than a canvas. 看起来他们使用div作为容器而不是画布。 Try this: 尝试这个:
<div id="gridalea" width="175px" height="720px"></div>
我不得不将<canvas>
更改为<div>
因为Kinetic JS使用div容器,而且我还必须在我的脚本标签中添加defer="defer"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.