Skip to content

Commit 226904b

Browse files
committed
make navbar-width resizable
1 parent 00a8a2b commit 226904b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

css/sidebar.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@
88
border-top-right-radius: 10px;
99
font-size: 12px;
1010
overflow-y: auto;
11+
overflow-x: hidden;
1112
transition: background-color 0.3s ease-in-out, padding 0.3s ease, max-width 0.3s ease, opacity 0.3s ease-in-out, visibility 0.3s step-end;
13+
}
14+
15+
#sidebar::before {
16+
content: '';
17+
background-color: #ccc;
18+
position: absolute;
19+
right: 0px;
20+
width: 4px;
21+
height: 100%;
22+
cursor: ew-resize;
1223
}

obsidian-page.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,29 @@ function toggleViewExam() {
375375
}, 1000);
376376
});
377377
}
378+
379+
/*
380+
* This script is used to resize the right panel by dragging the border.
381+
*/
382+
const BORDER_SIZE = 4;
383+
const panel = document.getElementById("sidebar");
384+
385+
let m_pos;
386+
function resize(e){
387+
const dx = m_pos - e.x;
388+
m_pos = e.x;
389+
panel.style.width = (parseInt(getComputedStyle(panel, '').width) - dx) + "px";
390+
}
391+
392+
panel.addEventListener("mousedown", function(e){
393+
const cs = getComputedStyle(panel, '')
394+
const w = parseInt(cs.width) + parseInt(cs.paddingLeft) + parseInt(cs.paddingRight)
395+
if (e.offsetX >= w - BORDER_SIZE) {
396+
m_pos = e.x;
397+
document.addEventListener("mousemove", resize, false);
398+
}
399+
}, false);
400+
401+
document.addEventListener("mouseup", function(){
402+
document.removeEventListener("mousemove", resize, false);
403+
}, false);

0 commit comments

Comments
 (0)