art.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Art page — vanilla JS (no jQuery, no Bootstrap carousel).
  2. // Navbar hide/show on scroll (ported from the shared jQuery dw_hidenav).
  3. (function () {
  4. const navbar = document.querySelector('.navbar');
  5. if (!navbar) return;
  6. const title = document.querySelector('.site-title a');
  7. const headerHeight = navbar.offsetHeight;
  8. let previousTop = 0;
  9. window.addEventListener('scroll', function () {
  10. const currentTop = window.scrollY;
  11. if (currentTop < previousTop) {
  12. if (currentTop > 0 && navbar.classList.contains('fixed')) {
  13. navbar.classList.add('visible');
  14. if (title) title.classList.remove('light');
  15. } else {
  16. navbar.classList.remove('visible', 'fixed');
  17. }
  18. } else {
  19. navbar.classList.remove('visible');
  20. if (currentTop > headerHeight && !navbar.classList.contains('fixed')) {
  21. navbar.classList.add('fixed');
  22. }
  23. }
  24. previousTop = currentTop;
  25. }, { passive: true });
  26. })();
  27. // Gallery — scroll-snap prev/next buttons + arrow keys (replaces the BS carousel).
  28. (function () {
  29. const track = document.querySelector('.dw-carousel-track');
  30. if (!track) return;
  31. const step = () =>
  32. track.firstElementChild
  33. ? track.firstElementChild.getBoundingClientRect().width
  34. : track.clientWidth;
  35. const scroll = (dir) => track.scrollBy({ left: dir * step(), behavior: 'smooth' });
  36. const prev = document.querySelector('.dw-carousel-prev');
  37. const next = document.querySelector('.dw-carousel-next');
  38. if (prev) prev.addEventListener('click', () => scroll(-1));
  39. if (next) next.addEventListener('click', () => scroll(1));
  40. document.addEventListener('keydown', function (e) {
  41. if (e.key === 'ArrowRight') scroll(1);
  42. else if (e.key === 'ArrowLeft') scroll(-1);
  43. });
  44. })();