Raphael.js,清除画布的问题
myraphael.js:
var raphael_test=function(){
var canvas = Raphael("my-canvas", width, height);
return {
startToDraw: function(){
//canvas.clear() //Error happend when mouse click more than once
canvas.rect(10, 10, 50, 50);
}
};
}();
draw.js:
var btn=$('#btn');
btn.click(function(){
raphael_test.startToDraw();
});
index.html:
<body>
<div id="my-canvas"></div>
<input type="button" id="btn"></input>
<script src="raphael-min.js"></script>
<script src="myraphael.js"></script>
<script src="draw.js"></script>
</body>
每次单击按钮时,我想首先清除之前的绘制,然后再次绘制矩形。
我在 myraphael.js 中的 canvas.rect(10, 10, 50, 50);
之前实现了 clear 部分。但是当鼠标多次单击按钮时,我收到来自 firebug 的错误:
raphael-min.js 是从 raphael 官方页面下载的 Raphael 库。
我不明白这个错误,也不知道如何消除它......
myraphael.js:
var raphael_test=function(){
var canvas = Raphael("my-canvas", width, height);
return {
startToDraw: function(){
//canvas.clear() //Error happend when mouse click more than once
canvas.rect(10, 10, 50, 50);
}
};
}();
draw.js:
var btn=$('#btn');
btn.click(function(){
raphael_test.startToDraw();
});
index.html:
<body>
<div id="my-canvas"></div>
<input type="button" id="btn"></input>
<script src="raphael-min.js"></script>
<script src="myraphael.js"></script>
<script src="draw.js"></script>
</body>
Every time when button clicked, I would like to first clear the previous draw, then draw the rectangular again.
I implement the clear part before canvas.rect(10, 10, 50, 50);
in myraphael.js. But when mouse click on the button more than once, I got error from firebug:
raphael-min.js is the Raphael library download from raphael official page.
I don't understand this error, and have no idea how to get rid of it...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
卡瓦斯!=纸。这是一个命名问题。
顺便说一句:请确保所有 dom 对象都已正确加载,并且您的 js 被..
cavas != paper. this is a naming issue.
btw: please make sure that all dom-objects are loaded properly and your js is wrapped by..
canvas.clear()
是正确的,但只能在myraphael.js
中访问。因此,向其添加一个clear
函数:canvas.clear()
is correct, but it is only accessible inmyraphael.js
. So, add aclear
function to it: