在画布圈内单击时打开弹出窗口

时间:2014-06-12 10:36:31

标签: javascript css html5 canvas popup

我想在用户点击圈内时打开一个弹出窗口,你能告诉我该怎么做吗?

以下是圈子的代码:

<!DOCTYPE html>
<html>
<body>


<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.beginPath();
ctx.arc(100,75,50,0,2*Math.PI);
ctx.stroke();

</script> 

</body>
</html>

1 个答案:

答案 0 :(得分:1)

单击画布选项卡区域时,我弹出了一个弹出框。但是,如果点击该圈子,请使用此参考链接http://www.w3schools.com/tags/tag_map.asp

您应该在canvas标签

中添加以下内容
onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';

即,

<canvas id="myCanvas" onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';" width="300" height="150" style="border:1px solid #d3d3d3;" >
Your browser does not support the HTML5 canvas tag.</canvas>

并创建两个id为'light'和'fade'

的div
<div id="light" class="white_content"><a href = "javascript:void(0)" onclick = "document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'">Close</a><p>Content goes here</p></div>

<div id="fade" class="black_overlay" onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'"></div>

并编写如下的CSS。

<style type="text/css">
        .black_overlay{
display: none;
position: fixed;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}

.white_content {
display: none;
position: fixed;
top: 10%;
left: 25%;
width: 50%;
height: 500px;
padding: 16px;
border: 13px solid #808080;
background-color: white;
z-index:1002;
overflow: auto;
}
    </style>