Skip to content

Commit

Permalink
fix: 标注目录滚动无效、点击跳转失效
Browse files Browse the repository at this point in the history
  • Loading branch information
Higurashi-kagome committed Sep 7, 2024
1 parent f287ca4 commit 85543f2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
38 changes: 18 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@
"sweetalert2": "^9.15.1",
"terser-webpack-plugin": "^5.3.1",
"ts-loader": "^9.2.9",
"typescript": "^4.6.3",
"typescript": "^5.4.5",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.8.1",
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@types/lodash": "^4.17.7",
"lodash": "^4.17.21",
"@types/nunjucks": "^3.2.3",
"lodash": "^4.17.21",
"nunjucks": "^3.2.4"
}
}
17 changes: 11 additions & 6 deletions src/content/modules/content-notesMenu.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* 给标注添加目录 */
import $ from 'jquery'
import { getCurrentChapTitle, loadCSS } from './content-utils'
import { noteBtnClassName } from '../../common/constants'
import {getCurrentChapTitle, loadCSS} from './content-utils'
import {noteBtnClassName} from '../../common/constants'

function initNotesMenu() {
console.log('initNotesMenu')
Expand All @@ -28,26 +28,31 @@ function initNotesMenu() {
const ul = $(`<ul id='${titleScrollSelector.replace('#', '')}'></ul>`).prependTo('#noteTools')
const curChapTitle = getCurrentChapTitle()
$('.sectionListItem_title').each((idx, titleEl) => {
// 标记当前章节
// 标记当前章节
const titleText = titleEl.textContent
const className = (titleText === curChapTitle) ? 'current' : ''
// 生成目录
const li = $(`<li><a class='${className}'>${titleText}</a></li>`).click(() => {
const li = $(`<li><a class='${className}'>${titleText}</a></li>`).on('click', () => {
console.log('click titleText', titleText)
console.log('click element into view', titleEl.parentElement)
// 标题被搜索框排除时也能够跳转
const titleParent = $(titleEl.parentElement!)
const isHide = titleParent.css('display') === 'none'
if (isHide) titleParent.css('display', 'block')
titleEl.parentElement!.scrollIntoView({ behavior: 'smooth' })
titleEl.parentElement!.scrollIntoView()
if (isHide) titleParent.css('display', 'none')
ul.toggle()
})
ul.append(li)
})
// 处理滚动不生效
ul.get(0)?.addEventListener('mousewheel', e => e.stopPropagation())
ul.get(0)?.addEventListener('DOMMouseScroll', e => e.stopPropagation())
btn.on('click', () => { // “目录”按钮点击事件
$(titleScrollSelector).toggle()
})
}, false)
})
}

export { initNotesMenu }
export {initNotesMenu}
Binary file modified wereader.zip
Binary file not shown.

0 comments on commit 85543f2

Please sign in to comment.