我复制了 Fabricjs 提供的代码并将其放入名为 Fabric.js 的文件中。然后我制作了一个名为 Canvas.js 的文件。我已经将两者都导入了我的 HTML 文件,并试图打印出一个矩形,但没有任何效果。我究竟做错了什么?
HTML:
<!doctype html>
<html lang="en";>
<head>
<meta charset="utf-8" />
<title>CustomCase</title>
<link rel="stylesheet" href="HeaderFooter.css">
<link rel="stylesheet" href="SkapaDesign.css">
<script src="Fabric.js"></script>
<script src="Canvas.js"></script>
</head>
<body>
<div id="Wrapper">
<header id="Header"></header>
<section id="Body">
<div id="LeftColumn">
<canvas id="Canvas"></canvas>
</div>
</section>
<footer id="Footer"></footer>
</div>
</body>
</html>
CSS:
#Body{
height: 675px;
}
#LeftColumn{
float: left;
width: 355px;
margin-top: 20px;
}
#Canvas{
float: left;
margin-left: 15px;
overflow: hidden;
}
JavaScript:
$(document).ready(function(){
var canvas = new fabric.Canvas('Canvas');
var rect = new fabric.Rect({
top: 100,
left: 100,
width: 60,
height: 70,
fill: 'red'
});
canvas.add(rect);
});