-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
107 lines (86 loc) · 3 KB
/
demo.html
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
<!doctype html>
<html>
<head>
<title>CursorLib Demo</title>
<style>
html, body {
font-family: Arial, sans-serif;
color: #333;
background: #fff;
text-align: center;
}
canvas {
border: silver solid 1px;
margin: 30px 0;
}
.cursorarea {
display: inline-block;
width: 400px;
height: 200px;
line-height: 200px;
border: silver solid 1px;
font-size: 12pt;
margin: 5px;
cursor: not-allowed;
color: gray;
position: relative;
border-radius: 5px;
}
.form {
margin-bottom: 30px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<div class="form">
<label for="cursor_size">Cursor size:</label>
<input type="text" name="cursor_size" id="cursor_size" value="64" />
<button id="cursor_size_apply">Apply</button>
</div>
<div id="cursor_curblob" class="cursorarea">Put mouse here</div>
<script src="dist/cursorlib.js"></script>
<script>
var canvas = document.getElementById("canvas");
function draw_cursor(size) {
var size = size - (1-size%2);
canvas.width = size;
canvas.height = size;
var ctx = canvas.getContext("2d");
ctx.save();
ctx.strokeStyle = "red";
ctx.lineWidth = 2;
ctx.translate(size/2, size/2);
ctx.beginPath();
ctx.arc(0, 0, size/2-1|0, 0, 2*Math.PI);
ctx.stroke();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, -3);
ctx.lineTo(0, 3);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-3, 0);
ctx.lineTo(3, 0);
ctx.stroke();
ctx.restore();
}
function apply_cursor() {
var element = document.getElementById("cursor_curblob");
var cursor = cursorLib.canvasToCssCursorProperty(
canvas, canvas.width/2, canvas.height/2, "crosshair");
element.style.cursor = cursor;
}
document.getElementById("cursor_size_apply").onclick = function() {
draw_cursor(parseInt(document.getElementById("cursor_size").value));
apply_cursor();
}
document.getElementById("cursor_size").onchange = function() {
draw_cursor(parseInt(document.getElementById("cursor_size").value));
apply_cursor();
}
draw_cursor(64);
apply_cursor();
</script>
</body>
</html>