site.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
  2. // for details on configuring this project to bundle and minify static web assets.
  3. // Write your JavaScript code.
  4. class NavMenu {
  5. constructor() {
  6. this.$menu = document.getElementById("navMenu");
  7. this.isDown = false;
  8. this.startX = 0;
  9. this.scrollLeft = 0;
  10. this.setEvent();
  11. }
  12. setEvent() {
  13. this.$menu.addEventListener('mousedown', (e) => this.mouseDown(e));
  14. this.$menu.addEventListener('mouseleave', () => this.mouseLeave());
  15. this.$menu.addEventListener('mouseup', () => this.mouseUp());
  16. this.$menu.addEventListener('mousemove', (e) => this.mouseMove(e));
  17. this.$menu.addEventListener('wheel', (e) => this.mouseWheel(e));
  18. }
  19. mouseWheel(e) {
  20. e.preventDefault(); // 기본 휠 스크롤 동작을 방지
  21. this.$menu.scrollLeft += (e.deltaY * 2); // 휠 속도 조정
  22. }
  23. mouseDown(e) {
  24. this.isDown = true;
  25. this.$menu.classList.add('active');
  26. this.startX = (e.pageX - this.$menu.offsetLeft);
  27. this.scrollLeft = this.$menu.scrollLeft;
  28. }
  29. mouseLeave() {
  30. this.isDown = false;
  31. this.$menu.classList.remove('active');
  32. }
  33. mouseUp() {
  34. this.isDown = false;
  35. this.$menu.classList.remove('active');
  36. }
  37. mouseMove(e) {
  38. if (!this.isDown) {
  39. return;
  40. }
  41. e.preventDefault();
  42. const x = (e.pageX - this.$menu.offsetLeft);
  43. const walk = ((x - this.startX) * 3); // 스크롤 속도 조정
  44. this.$menu.scrollLeft = (this.scrollLeft - walk);
  45. }
  46. }
  47. const navMenu = new NavMenu();
  48. $(function () {
  49. const dropdownElementList = document.querySelectorAll('.dropdown-toggle');
  50. const dropdownList = [...dropdownElementList].map(dropdownToggleEl => new bootstrap.Dropdown(dropdownToggleEl));
  51. });