-3
A
回答
2
第一步:三角
<!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>
你只需要remplace from_x_n與真正的價值。
第二站:檢測點擊
c.addEventListener('click', function(event) {
console.log(event.pageX);
console.log(event.pageY);
//here you must check x and y
});
檢查單擊訪問此鏈接:using canvas drawing square and triangle with customize color when click bottton和專門http://jsfiddle.net/rcondori/3gmosgq7/
_ 「什麼想法?」 _做什麼?你沒有清楚地解釋你的問題,你只是談論「三角形」,「地區」,「頁面」。請給我們更多的細節,並張貼你迄今爲止的代碼,如果你嘗試了任何東西。我懷疑任何人都只能回答這些信息。 – blex 2015-03-31 12:16:55
對不起,我的英語不太好,簡單我想建立這個建設,我不能選擇更好的解決方案 – user3006575 2015-03-31 12:20:30
_「建設這個建設」_。當然,但是這個_construction_一旦建成了,它應該做些什麼呢?現在,這只是一個圖像,我們不知道應該做什麼,或者應該用什麼來代替「1」,「2」和「3」......無論如何,如果你想要一個答案,你可能不得不提供更多解釋。 – blex 2015-03-31 12:28:05