如何最好地制作此解决方案 javaScript 或 canvas
how best make this solution javaScript or canvas
有活动区域的三角形支持其他分辨率有什么想法吗?
区域与其他页面的链接。
我想建这个建筑,告诉我正确的方法
第一步:三角形
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300" 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.lineWidth = "1";
ctx.strokeStyle = "#d3d3d3"; // Green path
ctx.moveTo(from_x_1, from_y_1);
ctx.lineTo(to_x_1, to_y_1);
ctx.moveTo(from_x_2, from_y_2);
ctx.lineTo(to_x_2, to_y_2);
ctx.moveTo(from_x_3, from_y_3);
ctx.lineTo(to_x_3, to_y_3);
ctx.stroke(); // Draw it
</script>
</body>
</html>
您只需要用实际值替换 from_x_n。
第二站:检测点击
c.addEventListener('click', function(event) {
console.log(event.pageX);
console.log(event.pageY);
//here you must check x and y
});
检查单击访问此 link : using canvas drawing square and triangle with customize color when click bottton and specially http://jsfiddle.net/rcondori/3gmosgq7/
有活动区域的三角形支持其他分辨率有什么想法吗? 区域与其他页面的链接。 我想建这个建筑,告诉我正确的方法
第一步:三角形
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="300" 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.lineWidth = "1";
ctx.strokeStyle = "#d3d3d3"; // Green path
ctx.moveTo(from_x_1, from_y_1);
ctx.lineTo(to_x_1, to_y_1);
ctx.moveTo(from_x_2, from_y_2);
ctx.lineTo(to_x_2, to_y_2);
ctx.moveTo(from_x_3, from_y_3);
ctx.lineTo(to_x_3, to_y_3);
ctx.stroke(); // Draw it
</script>
</body>
</html>
您只需要用实际值替换 from_x_n。
第二站:检测点击
c.addEventListener('click', function(event) {
console.log(event.pageX);
console.log(event.pageY);
//here you must check x and y
});
检查单击访问此 link : using canvas drawing square and triangle with customize color when click bottton and specially http://jsfiddle.net/rcondori/3gmosgq7/