1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<style>
*{
margin: 10;
padding: 10;
box-sizing: border-box;
}
#canvas{
border: 2px solid black;
}
.coord {
opacity: 0.5;
-webkit-transition: opacity .1s linear;
-moz-transition: opacity .1s linear;
-o-transition: opacity .1s linear;
transition: opacity .1s linear;
width: 100px;
border: solid 1px black;
}
</style>
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<canvas id="canvas"></canvas>
<ol id="coords"></ol>
<script>
window.addEventListener("load", () => {
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext("2d");
var countClick = 0;
var count = 0;
var x, y;
canvas.height = screen.height;
canvas.width = screen.width;
let painting = false;
function startPosition(e){
x = e.clientX;
y = e.clientY;
if(countClick < 3){
painting = true;
}
else{
painting=false
}
countClick++;
draw(e);
}
$(document).ready(function() {
$(document).click(function(e) {
count++;
mark = $("<span>").css({
'position':'absolute',
'border':'solid 2px #cc00cc',
'border-radius':'20px',
'width':'17px',
'height':'17px',
top: e.pageY-10,
left: e.pageX-10
});
if(count < 4){
coord = $("<li>" + e.pageX + " x " + e.pageY + "</li>");
$(coord).attr('id', "coord" + count);
$(coord).addClass('coord');
$(coord).css('display', 'none');
$(coord).hover(coord_focus, coord_unfocus);
$("ol#coords").append(coord);
$(coord).show('slow');
}
});
});
function coord_focus(e) {
$(this).addClass('focused-coord');
var id = $(this).attr('id');
$("div#marks .mark#mark" + id.charAt( id.length-1 )).addClass('focused-mark');
}
function coord_unfocus(e) {
$(this).removeClass('focused-coord');
var id = $(this).attr('id');
$("div#marks .mark#mark" + id.charAt( id.length-1 )).removeClass('focused-mark');
}
function draw(e){
if (!painting) return;
ctx.lineWidth = 2;
ctx.lineCap = "round";
ctx.strokeStyle="red";
ctx.beginPath();
ctx.arc(e.clientX, e.clientY, 22, 0, 2 * Math.PI);
ctx.stroke();
}
canvas.addEventListener("mousedown", startPosition);
})
</script>
</body>
</html> |