scrollables.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const scrollButtons = `
  2. <a href="#up" id="scroll-up" class="btn btn-primary btn-sm" role="button" aria-pressed="true" style="display: sticky; position: fixed; bottom: 3rem; right: 1rem;">
  3. <span class="ing-caret ing-rotate-180 ing-fw"></span>
  4. </a>
  5. <a href="#down" id="scroll-down" class="btn btn-primary btn-sm" role="button" aria-pressed="true" style="display: sticky; position: fixed; bottom: 1rem; right: 1rem;">
  6. <span class="ing-caret ing-fw"></span>
  7. </a>
  8. `
  9. document.body.insertAdjacentHTML('beforeend', scrollButtons);
  10. const scroll_up = document.querySelector('#scroll-up');
  11. const scroll_down = document.querySelector('#scroll-down');
  12. scroll_up.style.transition = scroll_down.style.transition = 'display 1.5s ease-in-out';
  13. scroll_up.style.display = scroll_down.style.display = 'none';
  14. scroll_up.addEventListener('click', () =>
  15. window.scrollTo({ top: 0, behavior: 'smooth' }))
  16. scroll_down.addEventListener('click', () =>
  17. window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }))
  18. const check = () => {
  19. scroll_down.style.display = (window.scrollY + window.innerHeight) > document.body.scrollHeight * .8 ? 'none' : 'block'
  20. scroll_up.style.display = (window.scrollY) < document.body.scrollHeight * .2 ? 'none' : 'block'
  21. }
  22. ['scroll', 'resize'].forEach(e => window.addEventListener(e, check))
  23. <<<<<<< HEAD
  24. =======
  25. document.addEventListener('DOMContentLoaded', function () {
  26. const links = document.querySelectorAll('a');
  27. links.forEach(function (link) {
  28. link.addEventListener('click', function (event) {
  29. // event.preventDefault();
  30. });
  31. });
  32. });
  33. >>>>>>> 7688f1aac1824c234bc5f19b154e9ad1f4808d4f