-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: delete content in the dist folder * fix: delete content in the dist folder * fix: not ignore the dist folder * feat: generate build
- Loading branch information
1 parent
e523254
commit 56366f7
Showing
6 changed files
with
4,100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ pnpm-debug.log* | |
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict'; | ||
|
||
class VanillaScrollspy { | ||
constructor({ menu, speed = 2000, easing = 'easeOutSine' }) { | ||
this.$menu = menu; | ||
this.speed = speed; | ||
this.easing = easing; | ||
} | ||
|
||
scrollToY(targetY = 0) { | ||
let currentTime = 0; | ||
const scrollTargetY = targetY; | ||
const scrollY = window.scrollY || document.documentElement.scrollTop; | ||
const time = Math.max( | ||
0.1, | ||
Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8) | ||
); | ||
|
||
const easingEquations = { | ||
easeOutSine(pos) { | ||
return Math.sin(pos * (Math.PI / 2)) | ||
}, | ||
|
||
easeInOutSine(pos) { | ||
return -0.5 * (Math.cos(Math.PI * pos) - 1) | ||
}, | ||
|
||
easeInOutQuint(pos) { | ||
if ((pos /= 0.5) < 1) return 0.5 * pos ** 5 | ||
return 0.5 * ((pos - 2) ** 5 + 2) | ||
} | ||
}; | ||
|
||
const tick = () => { | ||
currentTime += 1 / 60; | ||
|
||
const p = currentTime / time; | ||
const t = easingEquations[this.easing](p); | ||
|
||
if (p < 1) { | ||
window.requestAnimationFrame(tick); | ||
window.scrollTo(0, scrollY + (scrollTargetY - scrollY) * t); | ||
return | ||
} | ||
|
||
window.scrollTo(0, scrollTargetY); | ||
}; | ||
|
||
tick(); | ||
} | ||
|
||
menuControl() { | ||
const $links = this.$menu.querySelectorAll('a[href^="#"]'); | ||
const scrollPos = window.scrollY || document.documentElement.scrollTop; | ||
|
||
$links.forEach((link) => { | ||
const $elem = document.querySelector(link.getAttribute('href')); | ||
|
||
return $elem.offsetTop <= scrollPos && | ||
$elem.offsetTop + $elem.clientHeight > scrollPos | ||
? link.classList.add('active') | ||
: link.classList.remove('active') | ||
}); | ||
} | ||
|
||
animated() { | ||
const $links = this.$menu.querySelectorAll('a[href^="#"]'); | ||
const self = this; | ||
|
||
function control(e) { | ||
e.preventDefault(); | ||
const $target = document.querySelector(this.hash); | ||
self.scrollToY($target.offsetTop); | ||
} | ||
|
||
$links.forEach((link) => link.addEventListener('click', control)); | ||
} | ||
|
||
init() { | ||
this.animated(); | ||
document.addEventListener('scroll', () => this.menuControl()); | ||
} | ||
} | ||
|
||
function vanillaScrollspy(...args) { | ||
return new VanillaScrollspy(...args) | ||
} | ||
|
||
module.exports = vanillaScrollspy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
class VanillaScrollspy { | ||
constructor({ menu, speed = 2000, easing = 'easeOutSine' }) { | ||
this.$menu = menu; | ||
this.speed = speed; | ||
this.easing = easing; | ||
} | ||
|
||
scrollToY(targetY = 0) { | ||
let currentTime = 0; | ||
const scrollTargetY = targetY; | ||
const scrollY = window.scrollY || document.documentElement.scrollTop; | ||
const time = Math.max( | ||
0.1, | ||
Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8) | ||
); | ||
|
||
const easingEquations = { | ||
easeOutSine(pos) { | ||
return Math.sin(pos * (Math.PI / 2)) | ||
}, | ||
|
||
easeInOutSine(pos) { | ||
return -0.5 * (Math.cos(Math.PI * pos) - 1) | ||
}, | ||
|
||
easeInOutQuint(pos) { | ||
if ((pos /= 0.5) < 1) return 0.5 * pos ** 5 | ||
return 0.5 * ((pos - 2) ** 5 + 2) | ||
} | ||
}; | ||
|
||
const tick = () => { | ||
currentTime += 1 / 60; | ||
|
||
const p = currentTime / time; | ||
const t = easingEquations[this.easing](p); | ||
|
||
if (p < 1) { | ||
window.requestAnimationFrame(tick); | ||
window.scrollTo(0, scrollY + (scrollTargetY - scrollY) * t); | ||
return | ||
} | ||
|
||
window.scrollTo(0, scrollTargetY); | ||
}; | ||
|
||
tick(); | ||
} | ||
|
||
menuControl() { | ||
const $links = this.$menu.querySelectorAll('a[href^="#"]'); | ||
const scrollPos = window.scrollY || document.documentElement.scrollTop; | ||
|
||
$links.forEach((link) => { | ||
const $elem = document.querySelector(link.getAttribute('href')); | ||
|
||
return $elem.offsetTop <= scrollPos && | ||
$elem.offsetTop + $elem.clientHeight > scrollPos | ||
? link.classList.add('active') | ||
: link.classList.remove('active') | ||
}); | ||
} | ||
|
||
animated() { | ||
const $links = this.$menu.querySelectorAll('a[href^="#"]'); | ||
const self = this; | ||
|
||
function control(e) { | ||
e.preventDefault(); | ||
const $target = document.querySelector(this.hash); | ||
self.scrollToY($target.offsetTop); | ||
} | ||
|
||
$links.forEach((link) => link.addEventListener('click', control)); | ||
} | ||
|
||
init() { | ||
this.animated(); | ||
document.addEventListener('scroll', () => this.menuControl()); | ||
} | ||
} | ||
|
||
function vanillaScrollspy(...args) { | ||
return new VanillaScrollspy(...args) | ||
} | ||
|
||
export { vanillaScrollspy as default }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.