Javascript 画布中的文本是否使用jQuery按时间顺序显示?
小提琴: 我想让隐藏的画布显示出来,当我点击“否”按钮时,页脚隐藏起来。但不知怎的,它们最终都消失了 好处:如何使html画布上的java单词按时间顺序出现(和消失)Javascript 画布中的文本是否使用jQuery按时间顺序显示?,javascript,jquery,html,css,canvas,Javascript,Jquery,Html,Css,Canvas,小提琴: 我想让隐藏的画布显示出来,当我点击“否”按钮时,页脚隐藏起来。但不知怎的,它们最终都消失了 好处:如何使html画布上的java单词按时间顺序出现(和消失) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<body>
<div id="canvas" style="display: block;">
<canvas id="myCanvas" height="300" width="500"></canvas>
</div>
<div id="buttons">
<button class="clickBoo" style="margin-top: 40px;">No</button>
</div>
<footer class="change">
Revised June 7th
</footer>
</body>
$(document).ready(function() {
$(function() {
var canvas = document.getElementById("myCanvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.font="30px Helvetica";
ctx.fillStyle = "white";
ctx.fillText ('Boo!',400,50);
ctx.fillText ('Boo!',10,200);
ctx.fillText ('Tea?',300,200);
ctx.fillText ('No?',200,400);
ctx.fillText ('Sorry if I scared you.',20,40);
}
});
$(".clickBoo").click(function() {
$(".change").toggle("changed");
$("#myCanvas").toggle("show");
});
});
不
6月7日修订
$(文档).ready(函数(){
$(函数(){
var canvas=document.getElementById(“myCanvas”);
if(canvas.getContext){
var ctx=canvas.getContext(“2d”);
ctx.font=“30px Helvetica”;
ctx.fillStyle=“白色”;
ctx.fillText('Boo!',400,50);
ctx.fillText('Boo!',10200);
ctx.fillText('Tea?',300200);
ctx.fillText('No?',200400);
ctx.fillText('如果我吓到你了,对不起',20,40);
}
});
$(“.clickBoo”)。单击(函数(){
$(“.change”)。切换(“已更改”);
$(“我的画布”)。切换(“显示”);
});
});
此代码存在几个问题
show
类应用于画布不会产生任何效果我不知道你想用页脚做什么,但我认为你需要使用toggleClass(‘更改’)谢谢!因此,我根据您和@Jackson所说的进行了更改,如果没有css隐藏,它将显示为一个红色框,但是我如何使它在单击按钮后变得可见,而不是相反?只需将属性可见性:隐藏添加到画布{z-index:0;position:relative;}