Skip to content

Commit

Permalink
make navbar-width resizable
Browse files Browse the repository at this point in the history
  • Loading branch information
guFalcon committed Oct 7, 2024
1 parent 00a8a2b commit 226904b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
11 changes: 11 additions & 0 deletions css/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,16 @@
border-top-right-radius: 10px;
font-size: 12px;
overflow-y: auto;
overflow-x: hidden;
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;
}

#sidebar::before {
content: '';
background-color: #ccc;
position: absolute;
right: 0px;
width: 4px;
height: 100%;
cursor: ew-resize;
}
26 changes: 26 additions & 0 deletions obsidian-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,29 @@ function toggleViewExam() {
}, 1000);
});
}

/*
* This script is used to resize the right panel by dragging the border.
*/
const BORDER_SIZE = 4;
const panel = document.getElementById("sidebar");

let m_pos;
function resize(e){
const dx = m_pos - e.x;
m_pos = e.x;
panel.style.width = (parseInt(getComputedStyle(panel, '').width) - dx) + "px";
}

panel.addEventListener("mousedown", function(e){
const cs = getComputedStyle(panel, '')
const w = parseInt(cs.width) + parseInt(cs.paddingLeft) + parseInt(cs.paddingRight)
if (e.offsetX >= w - BORDER_SIZE) {
m_pos = e.x;
document.addEventListener("mousemove", resize, false);
}
}, false);

document.addEventListener("mouseup", function(){
document.removeEventListener("mousemove", resize, false);
}, false);

0 comments on commit 226904b

Please sign in to comment.