[英]Empty the content of a div using jQuery. Can not make it work
I use this example that allow me to draw into the canvas. 我使用此示例,使我可以绘制到画布中。 http://devfiles.myopera.com/articles/649/example2.html http://devfiles.myopera.com/articles/649/example2.html
However, I want to have a button that clears the content of it. 但是,我想要一个按钮来清除其内容。 This is what I did without luck. 这是我没有运气的事情。
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#clearme").click(function() {
var view = $('#imageView');
var context = view[0].getContext('2d');
context.clearRect(550, 550, view.width(), view.height());
});
});
<a href="#" id="clearme">clear</a>
<div id="container">
<canvas id="imageView" width="610" height="680">
</canvas>
</div>
What am I missing here? 我在这里想念什么?
Clear the canvas via its API instead: 而是通过其API清除画布:
var view = $('#imageView');
var context = view[0].getContext('2d');
context.clearRect(0, 0, view.width(), view.height());
You have to clear the canvas, empty()
is not what you're looking for. 您必须清除画布, empty()
不是您要的内容。 Do something like this: 做这样的事情:
var ctx = canvasEl.getContext('2d');
ctx.clearRect(0, 0, canvasEl.width, canvasEl.height);
ctx.beginPath();
Empty() wont clear a canvas. Empty()不会清除画布。 You'll have to use clearRect. 您将必须使用clearRect。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.