-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectInject.txt
73 lines (59 loc) · 1.83 KB
/
selectInject.txt
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
document.body.innerHTML = document.body.innerHTML + `
<style>
#selection {
position: absolute;
z-index: 99999999999999;
background: #e0eaf1;
border: 1px solid #0c65a5;
}
#selection.complete {
z-index: 99999999999999;
background: #E0F1E4;
border-color: #0CA50E;
}
</style>
<strong>Start coordinates:</strong><span id="start"></span><strong>End coordinates:</strong><span id="end"></span><div id="selection"></div>
`
var start = {};
var end = {};
var isSelecting = false;
$(window)
// Listen for selection
.on('mousedown', function($event) {
// Update our state
isSelecting = true;
$('#selection').removeClass('complete');
start.x = $event.pageX;
start.y = $event.pageY;
// Display data in UI
$('#start').text('(' + start.x + ',' + start.y + ')');
// Add selection to screen
$('#selection').css({
left: start.x,
top: start.y
});
})
// Listen for movement
.on('mousemove', function($event) {
// Ignore if we're not selecing
if (!isSelecting) { return; }
// Update our state
end.x = $event.pageX;
end.y = $event.pageY;
// Move & resize selection to reflect mouse position
$('#selection').css({
left: start.x < end.x ? start.x : end.x,
top: start.y < end.y ? start.y : end.y,
width: Math.abs(start.x - end.x),
height: Math.abs(start.y - end.y)
});
})
// listen for end
.on('mouseup', function($event) {
// Update our state
isSelecting = false;
$('#selection').addClass('complete');
// Display data in UI
$('#end').text('(' + end.x + ',' + end.y + ')');
console.log(end.x +":"+end.y);
});