-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
138 lines (117 loc) · 4.04 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Animated checkboxes and radio buttons</title>
<script src="jquery-2.0.3.js"></script>
<script src="drawAnimator.class.js"></script>
<style>
body{
font-family: arial;
}
.checkbox-canvas{
border: 1px solid rgb(0, 0, 0);
background: rgb(255, 255, 255);
margin: 0px;
padding: 0px;
}
.checkbox-canvas:hover{
}
.checkbox-canvas:focus{
outline: none;
}
label{
font-size: 16px;
margin-left: 6px;
}
#myCanvas{
border: 1px solid green;
background: black;
}
</style>
<script>
$(document).ready(function(){
$('input[type=checkbox]').each(function(key, checkbox){
var id = $(this).attr('id');
var canvasChekbox = '<canvas id="checkbox_canvas_'+id+'" width="15" height="15" class="checkbox-canvas" ></canvas>';
$(this).after(canvasChekbox);
$(this).css('display', 'none');
if(!$(this).prop('checked')){
$(this).prop('checked', false);
$(canvasChekbox).removeClass('checked');
resetCanvasCheckbox($('#checkbox_canvas_'+id));
}
else{
$(this).prop('checked', true);
$(this).addClass('checked');
animateCanvasChekbox($('#checkbox_canvas_'+id));
}
});
$('body').on('click', 'canvas.checkbox-canvas', function(){
handleCanvasCheckbox(this);
});
var test = new drawAnimator($('#myCanvas')[0], true);
test.drawAnimatedLine(10, 0, 0, 10, 13, 'yellow', 1);
test.drawAnimatedLine(10, 12, 9, 14, 5, 'yellow', 1);
});
function handleCanvasCheckbox(checkBoxCanvas){
var checkBoxCanvasID = $(checkBoxCanvas).attr('id');
originalCheckboxID = checkBoxCanvasID.replace("checkbox_canvas_","");
if($('#'+originalCheckboxID).prop('checked')){
$('#'+originalCheckboxID).prop('checked', false);
$(checkBoxCanvas).removeClass('checked');
resetCanvasCheckbox(checkBoxCanvas);
}
else{
$('#'+originalCheckboxID).prop('checked', true);
$(checkBoxCanvas).addClass('checked');
animateCanvasChekbox(checkBoxCanvas);
}
}
function resetCanvasCheckbox(checkBoxCanvas){
var id = $(checkBoxCanvas).attr('id');
var checkSign = new drawAnimator($('#'+id)[0], true);
checkSign.reset();
$(checkBoxCanvas).css('border', '1px solid');
}
function animateCanvasChekbox(checkBoxCanvas){
var id = $(checkBoxCanvas).attr('id');
var checkSign = new drawAnimator($('#'+id)[0], true);
checkSign.drawAnimatedLine(10, 4, 8, 8, 14, 'green', 1);
checkSign.drawAnimatedLine(10, 8, 14, 12, 2, 'green', 1);
$(checkBoxCanvas).css('border', '1px solid red');
}
</script>
<script>
$(document).ready(function(){
function writeMessage(message) {
$('#cor').html(message);
}
function getMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
return {
x: evt.clientX - rect.left,
y: evt.clientY - rect.top
};
}
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
canvas.addEventListener('mousemove', function(evt) {
var mousePos = getMousePos(canvas, evt);
var message = 'Mouse position: ' + mousePos.x + ',' + mousePos.y;
writeMessage(message);
}, false);
});
</script>
</head>
<body>
<form action="test.php" method="POST">
<input type="checkbox" id="test1" name="test[]" value="value1" ><label for="test1">Label1</label><br>
<input type="checkbox" id="test2" name="test[]" value="value2" ><label for="test2">Label2</label><br>
<input type="checkbox" id="test3" name="test[]" value="value3" ><label for="test3">Label3</label><br>
<input type="checkbox" id="test4" name="test[]" value="value4" checked ><label for="test4">Label4</label><br>
<input type="submit" value="Test">
</form>
<canvas id="myCanvas" width="15" height="15" ></canvas>
<div id="cor"></div>
</body>
</html>