mobile.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. window.addEventListener("load", function() {
  2. new Swiper("#swiper_1", {
  3. speed: 600,
  4. navigation: {
  5. nextEl: '.swiper-button-next',
  6. prevEl: '.swiper-button-prev',
  7. }
  8. });
  9. scrollInit();
  10. });
  11. // 맨 위로 버튼
  12. $(document).on("click", "#btnMoveTop", function () {
  13. $("html, body").animate({scrollTop: 0}, "fast");
  14. });
  15. let header = document.getElementsByTagName("header")[0];
  16. let nav = document.getElementsByTagName("nav")[0];
  17. let headerHeight = header.offsetHeight;
  18. let navHeight = nav.offsetHeight;
  19. window.onscroll = function () {
  20. scrollInit();
  21. };
  22. function scrollInit()
  23. {
  24. let windowTop = window.scrollY;
  25. let footHeight = document.getElementsByTagName("footer")[0].offsetTop;
  26. if (windowTop >= (headerHeight + navHeight)) {
  27. header.classList.add("position-fixed");
  28. nav.classList.add("position-fixed");
  29. }else{
  30. header.classList.remove("position-fixed");
  31. nav.classList.remove("position-fixed");
  32. }
  33. if((windowTop + window.innerHeight) > footHeight) {
  34. $("#btnMoveTop").css("position", "absolute");
  35. }else{
  36. $("#btnMoveTop").css("position", "fixed");
  37. }
  38. }