Wedding Invitation
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import './bootstrap';
  2. // resources/js/app.js
  3. import '@fortawesome/fontawesome-free/css/all.min.css';
  4. // Countdown date (adjust this date to your desired countdown target)
  5. const countdownDate = new Date('2024-08-17T11:00:00').getTime();
  6. // Update the countdown every second
  7. const countdownElement = document.getElementById('countdown');
  8. const countdownTimer = setInterval(() => {
  9. // Get the current date and time
  10. const now = new Date().getTime();
  11. // Calculate the time remaining
  12. const distance = countdownDate - now;
  13. // Calculate days, hours, minutes, and seconds
  14. const days = Math.floor(distance / (1000 * 60 * 60 * 24));
  15. const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  16. const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  17. const seconds = Math.floor((distance % (1000 * 60)) / 1000);
  18. // Format the countdown into a string
  19. const countdownHTML = `
  20. <div class="flex flex-col">
  21. <div class="flex gap-8 justify-center">
  22. <div class="font-medium text-gray-500">${days}</div>
  23. <div class="font-medium text-gray-500">:</div>
  24. <div class="font-medium text-gray-500">${hours.toString().padStart(2, '0')}</div>
  25. <div class="font-medium text-gray-500">:</div>
  26. <div class="font-medium text-gray-500">${minutes.toString().padStart(2, '0')}</div>
  27. <div class="font-medium text-gray-500">:</div>
  28. <div class="font-medium text-gray-500">${seconds.toString().padStart(2, '0')}</div>
  29. </div>
  30. <div class="flex gap-14 justify-center">
  31. <div class="font-medium text-gray-600">Hari</div>
  32. <div class="font-medium text-gray-600">Jam</div>
  33. <div class="font-medium text-gray-600">Minit</div>
  34. <div class="font-medium text-gray-600">Saat</div>
  35. </div>
  36. </div>
  37. `;
  38. // Display the countdown in the element
  39. countdownElement.innerHTML = countdownHTML;
  40. // If the countdown is over, clear the timer and display a message
  41. if (distance < 0) {
  42. clearInterval(countdownTimer);
  43. countdownElement.innerHTML = 'Majlis berlangsung';
  44. }
  45. }, 1000); // Update every second (1000 milliseconds)
  46. $(document).ready(function() {
  47. var audioElement = document.getElementById('player');
  48. var hasPlayed = false;
  49. var scrollCount = 0;
  50. var maxScrolls = 8;
  51. var scrollInterval = 200;
  52. var scrollAmount = window.innerHeight / 6;
  53. function playAudio() {
  54. if (!hasPlayed) {
  55. var playPromise = audioElement.play();
  56. if (playPromise !== undefined) {
  57. playPromise.then(function() {
  58. hasPlayed = true;
  59. }).catch(function(error) {
  60. console.log('Autoplay failed: ' + error);
  61. });
  62. }
  63. }
  64. }
  65. function smoothScroll() {
  66. if (!hasPlayed) {
  67. playAudio();
  68. scrollCount++;
  69. if (scrollCount >= maxScrolls) {
  70. playAudio();
  71. } else {
  72. var start = window.pageYOffset;
  73. var target = start + scrollAmount;
  74. var screenWidth = window.innerWidth;
  75. var duration;
  76. if (screenWidth < 600) {
  77. duration = 5000;
  78. } else if (screenWidth < 1200) {
  79. duration = 12000;
  80. } else {
  81. duration = 15000;
  82. }
  83. var startTime = null;
  84. function scrollStep(timestamp) {
  85. if (!startTime) startTime = timestamp;
  86. var progress = timestamp - startTime;
  87. var currentPosition = start + ((target - start) * (progress / duration));
  88. window.scrollTo(0, currentPosition);
  89. if (progress < duration) {
  90. requestAnimationFrame(scrollStep);
  91. } else {
  92. setTimeout(smoothScroll, scrollInterval);
  93. }
  94. }
  95. requestAnimationFrame(scrollStep);
  96. }
  97. }
  98. }
  99. function handleInteraction() {
  100. document.body.classList.remove('no-scroll');
  101. setTimeout(smoothScroll, scrollInterval);
  102. }
  103. window.addEventListener('click', function() {
  104. setTimeout(function() {
  105. document.getElementById('petalOverlay').style.display = 'block';
  106. }, 1000);
  107. });
  108. window.addEventListener('scroll', function() {
  109. if (window.pageYOffset === 0) {
  110. audioElement.pause();
  111. document.getElementById('petalOverlay').style.display = 'none';
  112. hasPlayed = false;
  113. document.body.classList.add('no-scroll');
  114. }
  115. });
  116. const observerOptions = {
  117. root: null,
  118. rootMargin: '0px',
  119. threshold: 0.1
  120. };
  121. const observer = new IntersectionObserver((entries, observer) => {
  122. entries.forEach(entry => {
  123. if (entry.isIntersecting) {
  124. entry.target.classList.add('fade-in');
  125. observer.unobserve(entry.target);
  126. }
  127. });
  128. }, observerOptions);
  129. document.querySelectorAll('.fade-element').forEach(element => {
  130. observer.observe(element);
  131. });
  132. $(window).scroll(function(event) {
  133. var distance = $(this).scrollTop() * 2;
  134. var left = 0 - distance;
  135. var right = 0 - distance;
  136. $('.left').css('left', left + "px");
  137. $('.right').css('right', right + "px");
  138. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  139. var isLeftOffScreen = leftPartRightEdge <= 0;
  140. if (isLeftOffScreen && left < 0) {
  141. $('.parent').removeClass('z-30');
  142. } else {
  143. $('.parent').addClass('z-30');
  144. }
  145. });
  146. $(window).trigger('scroll');
  147. });