Open popup when click inside canvas circle

核能气质少年 提交于 2019-12-12 02:47:14

问题


I want to open a popup when the user clicks inside the Circle, could you advise me how to do this please?

Here is the code for the circle:

<!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:


I made a popup box when clicking the canvas tab area. But if clicking the circle then use this reference link http://www.w3schools.com/tags/tag_map.asp

You should add the belowline inside canvas tag

onclick = "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';

i.e.,

<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>

and create two div with id as 'light' and 'fade'

<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>

and write the css like below.

<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>


来源:https://stackoverflow.com/questions/24182281/open-popup-when-click-inside-canvas-circle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!