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