简体   繁体   English

隐藏HTML5 Canvas元素

[英]Hide a HTML5 Canvas element

I try to use the HTML5 Canvas tag, until now I managed to do what I wanted. 我尝试使用HTML5 Canvas标签,直到现在我设法做我想要的。 But now I'm trying to hide in fade a Canvas element (context). 但现在我试图隐藏淡入Canvas元素(上下文)。 The retunred error is context.fadeOut is not a function . 返回的错误是context.fadeOut is not a function

See my draft here: http://jsfiddle.net/t46Ze/4/ 在这里查看我的草稿: http//jsfiddle.net/t46Ze/4/

Thanks for your help. 谢谢你的帮助。


EDIT > Here my initial wanted : http://jsfiddle.net/t46Ze/15/ 编辑>这里我最初想要的: http//jsfiddle.net/t46Ze/15/

EDIT > Here the Andrew proposition : http://jsfiddle.net/t46Ze/16/ (with comments) 编辑>这里安德鲁命题: http//jsfiddle.net/t46Ze/16/ (附评论)

You're trying to fade out the 2D context of the canvas, not the canvas element itself. 您试图淡出画布的2D上下文,而不是画布元素本身。 Fade out the element itself instead. 相反淡出元素本身。

$(canvas).fadeOut而不是context.fadeOut

You can just do exactly what you do to draw it, but in reverse, 你可以完全按照你的方式绘制它,但相反,

http://jsfiddle.net/t46Ze/15/ http://jsfiddle.net/t46Ze/15/

我在画布上尝试了下面的代码

<canvas id="newCanvas" style="display: none"></canvas>

You may want to try it with jQuery. 您可能想尝试使用jQuery。

<html>
<head>
    <!-- Path to your jQuery core js library or you can use one from Google.
    <script type="text/javascript" src="jquery.min.js" />
    <!-- Path to your jQuery UI js library or you can use one from Google.
    <script type="text/javascript" src="jquery-ui.min.js" />

</head>
<body>
   <canvas id="myCanvas" ..>..</canvas>
</body>
</html>

And when you want to fade it out, just call: 当你想淡出时,只需致电:

$("#myCanvas").fadeOut(2500); // 2 seconds and a half, for example

There are also other "effects" like: 还有其他“效果”,如:

$("#myCanvas").slideUp(1500); // 1 and a half seconds, for example

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

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