javascript 隐藏 HTML5 Canvas 元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8402836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:20:11  来源:igfitidea点击:

Hide a HTML5 Canvas element

javascripthtmlcanvashide

提问by Hyman NUMBER

I try to use the HTML5 Canvas tag, until now I managed to do what I wanted. But now I'm trying to hide in fade a Canvas element (context). The retunred error is context.fadeOut is not a function.

我尝试使用 HTML5 Canvas 标签,直到现在我设法做我想做的事。但现在我试图隐藏一个 Canvas 元素(上下文)淡入淡出。返回的错误是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/(有评论)

回答by James

You're trying to fade out the 2D context of the canvas, not the canvas element itself. Fade out the element itself instead.

您正在尝试淡出画布的 2D 上下文,而不是画布元素本身。而是淡出元素本身。

回答by Anders Tornblad

Do $(canvas).fadeOutinstead of context.fadeOut

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

回答by Andrew

You can just do exactly what you do to draw it, but in reverse,

你可以完全按照你的方式绘制它,但反过来,

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

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

回答by Rolice

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

回答by jijin george

I tried the below code in the canvas

我在画布中尝试了以下代码

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