1.3 (#38)
* Add cover page * Update doc * Add kbd style, resolve #37 * headling can cliked, resolve #36 * Update change log, close #35 * Update docs
This commit is contained in:
parent
b14fcf7d1c
commit
50addfdac6
14 changed files with 312 additions and 48 deletions
22
src/event.js
22
src/event.js
|
|
@ -23,11 +23,11 @@ export function scrollActiveSidebar () {
|
|||
|
||||
function highlight () {
|
||||
for (let i = 0, len = anchors.length; i < len; i += 1) {
|
||||
const node = anchors[i].parentNode
|
||||
const node = anchors[i]
|
||||
const bcr = node.getBoundingClientRect()
|
||||
|
||||
if (bcr.top < 10 && bcr.bottom > 10) {
|
||||
const li = nav[node.id]
|
||||
const li = nav[node.getAttribute('data-id')]
|
||||
|
||||
if (!li || li === active) return
|
||||
if (active) active.setAttribute('class', '')
|
||||
|
|
@ -40,9 +40,8 @@ export function scrollActiveSidebar () {
|
|||
}
|
||||
}
|
||||
|
||||
const dom = document.querySelector('main .content')
|
||||
dom.removeEventListener('scroll', highlight)
|
||||
dom.addEventListener('scroll', highlight)
|
||||
window.removeEventListener('scroll', highlight)
|
||||
window.addEventListener('scroll', highlight)
|
||||
highlight()
|
||||
}
|
||||
|
||||
|
|
@ -100,3 +99,16 @@ export function scroll2Top () {
|
|||
}
|
||||
cacheContentDOM.scrollTop = 0
|
||||
}
|
||||
|
||||
export function sticky () {
|
||||
const dom = document.querySelector('section.cover')
|
||||
const coverHeight = dom.getBoundingClientRect().height
|
||||
|
||||
return (function () {
|
||||
if (window.pageYOffset >= coverHeight || dom.classList.contains('hidden')) {
|
||||
document.body.classList.add('sticky')
|
||||
} else {
|
||||
document.body.classList.remove('sticky')
|
||||
}
|
||||
})()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue