Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

scroll-up.ts 607 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  1. export default function () {
  2. // function to scroll up to page top
  3. const PageTopBtn = document.getElementById('js-scroll-top')
  4. if (!PageTopBtn) return
  5. PageTopBtn.addEventListener('click', () => {
  6. window.scrollTo({
  7. top: 0,
  8. behavior: 'smooth',
  9. })
  10. })
  11. // show scroll button only when display is scroll down
  12. window.addEventListener('scroll', function () {
  13. const y = document.documentElement.scrollTop // get the height from page top
  14. if (y < 100) {
  15. PageTopBtn.classList.remove('show')
  16. } else if (y >= 100) {
  17. PageTopBtn.classList.add('show')
  18. }
  19. })
  20. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...