Skip to content

Commit 8ffc3c1

Browse files
committed
feat: tocbar style top should not be less than 0
1 parent 84ddb3b commit 8ffc3c1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

toc-bar.user.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// @license MIT
77
// @description A floating table of content widget
88
// @description:zh-CN 在页面右侧展示一个浮动的文章大纲目录
9-
// @version 1.4.2
9+
// @version 1.4.3
1010
// @match *://www.jianshu.com/p/*
1111
// @match *://cdn2.jianshu.io/p/*
1212
// @match *://zhuanlan.zhihu.com/p/*
@@ -381,7 +381,7 @@ a.toc-link {
381381

382382
const cachedPosition = POSITION_STORAGE.get(options.siteName)
383383
if (!isEmpty(cachedPosition)) {
384-
this.element.style.top = `${cachedPosition.top}px`
384+
this.element.style.top = `${Math.max(0, cachedPosition.top)}px`
385385
this.element.style.right = `${cachedPosition.right}px`
386386
} else if (options.hasOwnProperty('initialTop')) {
387387
this.element.style.top = `${options.initialTop}px`
@@ -458,7 +458,7 @@ a.toc-link {
458458
const deltaY = e.pageY - dragState.startMouseY
459459
// 要换算为 right 数字
460460
const newRight = dragState.startElementDisToRight - deltaX
461-
const newTop = dragState.startPositionY + deltaY
461+
const newTop = Math.max(0, dragState.startPositionY + deltaY)
462462
Object.assign(dragState, {
463463
curTop: newTop,
464464
curRight: newRight,

0 commit comments

Comments
 (0)