-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathySplit.html
66 lines (54 loc) · 1.67 KB
/
ySplit.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
<html><head>
<meta charset="utf-8" />
<style>
* { font-family: sans-serif; font-size: small; }
#main { position: relative; margin: 50px; height: 200px; }
/* CSS for sub panels */
#main *:nth-child(1) { background: lightgreen; }
#main *:nth-child(2) { background: lightyellow; }
</style>
</head><body>
<div id="main">
<div id="north">north</div>
<div id="south">south</div>
</div>
<script>
HTMLElement.prototype.ySplit = function(){
// Initialize
var north = this.children[0];
var south = this.children[1];
north.style = 'position: absolute; left: 0; right: 0; top:0; height: 25%; ';
south.style = 'position: absolute; left: 0; right: 0; bottom: 0; top: 25%';
var split = document.createElement('div');
split.style = 'position: absolute; left: 0; right:0; top:25%; height: 1.5em; cursor: row-resize; border-top: 2px solid grey; ';
this.appendChild(split);
var drag = null;
// Start drag
split.onmousedown = (event) => {
drag = event.clientY - this.offsetTop;
split.style.cursor = 'ns-resize';
}
// Move drag
this.onmousemove = (event) => {
if(drag && this.offsetTop <= event.clientY && event.clientY <= this.offsetTop+this.offsetHeight){
split.style.top = event.clientY - this.offsetTop;
north.style.height = event.clientY - this.offsetTop;
south.style.top = event.clientY - this.offsetTop + 2;
}
}
// End drag
onmouseup = (event) => {
drag = null;
split.style.cursor = 'row-resize';
}
// Show select
split.onmouseenter = (event) => {
split.style.background = 'rgba(0,0,0,0.1)';
}
split.onmouseleave = (event) => {
split.style.background = '';
}
}
document.getElementById('main').ySplit();
</script>
</body></html>