Skip to content

Commit ca20775

Browse files
committed
feat: optimize right edge distance while dragging
1 parent 27ce1b0 commit ca20775

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

toc-bar.user.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@
254254
return true
255255
}
256256

257+
/** 宽度,也用于计算拖动时的最小 right */
258+
const TOC_BAR_WIDTH = 340
259+
257260
// ---------------- TocBar ----------------------
258261
const TOC_BAR_STYLE = `
259262
.toc-bar {
@@ -263,7 +266,7 @@
263266
z-index: 9000;
264267
right: 5px;
265268
top: 80px;
266-
width: 340px;
269+
width: ${TOC_BAR_WIDTH}px;
267270
font-size: 14px;
268271
box-sizing: border-box;
269272
padding: 0 10px 10px 0;
@@ -525,7 +528,7 @@ a.toc-link {
525528
const deltaX = e.pageX - dragState.startMouseX
526529
const deltaY = e.pageY - dragState.startMouseY
527530
// 要换算为 right 数字
528-
const newRight = dragState.startElementDisToRight - deltaX
531+
const newRight = Math.max(30 - TOC_BAR_WIDTH, dragState.startElementDisToRight - deltaX)
529532
const newTop = Math.max(0, dragState.startPositionY + deltaY)
530533
Object.assign(dragState, {
531534
curTop: newTop,

0 commit comments

Comments
 (0)