Wedding Invitation
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

app.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. $(function() {
  47. var partLeftPos = 0;
  48. var partRightPos = 0;
  49. var isScrolling = false;
  50. var lastScrollTop = 0;
  51. function updatePositions() {
  52. var scrollTop = $(window).scrollTop();
  53. var distance = scrollTop * 2;
  54. var left = partLeftPos - distance;
  55. var right = partRightPos - distance;
  56. $('.left').css('left', left + "px");
  57. $('.right').css('right', right + "px");
  58. // Calculate boundaries
  59. var leftPartRightEdge = $('.left').offset().left + $('.left').outerWidth();
  60. // Check if both parts are completely off-screen
  61. var isLeftOffScreen = leftPartRightEdge <= 0;
  62. // Toggle visibility and z-index
  63. if (isLeftOffScreen && left < 0) {
  64. $('.parent').removeClass('z-30');
  65. } else {
  66. $('.parent').addClass('z-30');
  67. }
  68. }
  69. // Initial positions update
  70. updatePositions();
  71. // Debounce function for scroll events
  72. function debounce(func, delay) {
  73. var timeout;
  74. return function() {
  75. var context = this;
  76. var args = arguments;
  77. var later = function() {
  78. timeout = null;
  79. func.apply(context, args);
  80. };
  81. clearTimeout(timeout);
  82. timeout = setTimeout(later, delay);
  83. };
  84. }
  85. // Update positions on scroll using requestAnimationFrame for smoother animation
  86. function scrollHandler() {
  87. if (!isScrolling) {
  88. window.requestAnimationFrame(function() {
  89. updatePositions();
  90. isScrolling = false;
  91. });
  92. }
  93. isScrolling = true;
  94. }
  95. // Listen to scroll events and debounce them for better performance
  96. $(window).scroll(debounce(scrollHandler, 20));
  97. // Handle window resize to recalculate positions if needed
  98. $(window).resize(function() {
  99. updatePositions();
  100. });
  101. });
  102. document.addEventListener('click', function () {
  103. setTimeout(function () {
  104. document.getElementById('petalOverlay').style.display = 'block';
  105. }, 1000); // Delay of 1 second (1000 milliseconds)
  106. });
  107. document.addEventListener('DOMContentLoaded', function() {
  108. var audioElement = document.getElementById('player');
  109. var hasPlayed = false; // To ensure audio only plays once upon clicking and scrolling
  110. var scrollCount = 0;
  111. var maxScrolls = 8;
  112. var scrollInterval = 200; // Time in milliseconds between each scroll
  113. var scrollAmount = window.innerHeight / 6; // Amount to scroll per interval
  114. function playAudio() {
  115. if (!hasPlayed) {
  116. console.log('play')
  117. var playPromise = audioElement.play();
  118. if (playPromise !== undefined) {
  119. playPromise.then(function() {
  120. // Automatic playback started!
  121. hasPlayed = true; // Prevent further attempts to play
  122. }).catch(function(error) {
  123. // Automatic playback failed.
  124. console.log('Autoplay failed: ' + error);
  125. });
  126. }
  127. }
  128. }
  129. function smoothScroll() {
  130. if (!hasPlayed) {
  131. playAudio();
  132. scrollCount++;
  133. if (scrollCount >= maxScrolls) {
  134. playAudio();
  135. } else {
  136. var start = window.pageYOffset;
  137. var target = start + scrollAmount;
  138. // Set duration based on screen size
  139. var screenWidth = window.innerWidth;
  140. var duration;
  141. if (screenWidth < 600) {
  142. duration = 5000; // Smaller screen
  143. } else if (screenWidth < 1200) {
  144. duration = 12000; // Medium screen
  145. } else {
  146. duration = 15000; // Larger screen
  147. }
  148. var startTime = null;
  149. function scrollStep(timestamp) {
  150. if (!startTime) startTime = timestamp;
  151. var progress = timestamp - startTime;
  152. var currentPosition = start + ((target - start) * (progress / duration));
  153. window.scrollTo(0, currentPosition);
  154. if (progress < duration) {
  155. requestAnimationFrame(scrollStep);
  156. } else {
  157. setTimeout(smoothScroll, scrollInterval); // Continues scrolling after a delay
  158. }
  159. }
  160. requestAnimationFrame(scrollStep);
  161. }
  162. }
  163. }
  164. function playOnly() {
  165. if (!hasPlayed) {
  166. playAudio();
  167. scrollCount++;
  168. if (scrollCount >= maxScrolls) {
  169. playAudio();
  170. } else {
  171. setTimeout(playOnly, scrollInterval);
  172. }
  173. }
  174. }
  175. function handleInteraction() {
  176. document.body.classList.remove('no-scroll'); // Enable scrolling
  177. setTimeout(smoothScroll, scrollInterval); // Start smooth scrolling after initial delay
  178. }
  179. // Listen for click or touch event to start auto-scrolling
  180. window.addEventListener('click', handleInteraction);
  181. window.addEventListener('scroll', function() {
  182. if (window.pageYOffset === 0) {
  183. audioElement.pause();
  184. document.getElementById('petalOverlay').style.display = 'none';
  185. hasPlayed = false; // Reset to allow replay
  186. document.body.classList.add('no-scroll');
  187. }
  188. });
  189. // Intersection Observer for fading in elements
  190. const observerOptions = {
  191. root: null,
  192. rootMargin: '0px',
  193. threshold: 0.1
  194. };
  195. const observer = new IntersectionObserver((entries, observer) => {
  196. entries.forEach(entry => {
  197. if (entry.isIntersecting) {
  198. entry.target.classList.add('fade-in');
  199. observer.unobserve(entry.target);
  200. }
  201. });
  202. }, observerOptions);
  203. document.querySelectorAll('.fade-element').forEach(element => {
  204. observer.observe(element);
  205. });
  206. });