123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- import './bootstrap';
- //import 'resources/js/app.js';
- import '@fortawesome/fontawesome-free/css/all.min.css';
-
-
- //Countdown date (adjust this date to your desired countdown target)
- const countdownDate = new Date('2024-08-17T11:00:00').getTime();
-
- //Update the countdown every second
- const countdownElement = document.getElementById('countdown');
- const countdownTimer = setInterval(() => {
- //Get the current date and time
- const now = new Date().getTime();
-
- //Calculate the time remaining
- const distance = countdownDate - now;
-
- //Calculate days, hours, minutes, and seconds
- const days = Math.floor(distance / (1000 * 60 * 60 * 24));
- const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
- const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
- const seconds = Math.floor((distance % (1000 * 60)) / 1000);
-
- //Format the countdown into a string
- const countdownHTML = `
- <div class="flex flex-col">
- <div class="flex gap-8 justify-center">
- <div class="font-medium text-gray-500">${days}</div>
- <div class="font-medium text-gray-500">:</div>
- <div class="font-medium text-gray-500">${hours.toString().padStart(2, '0')}</div>
- <div class="font-medium text-gray-500">:</div>
- <div class="font-medium text-gray-500">${minutes.toString().padStart(2, '0')}</div>
- <div class="font-medium text-gray-500">:</div>
- <div class="font-medium text-gray-500">${seconds.toString().padStart(2, '0')}</div>
- </div>
- <div class="flex gap-14 justify-center">
- <div class="font-medium text-gray-600">Hari</div>
- <div class="font-medium text-gray-600">Jam</div>
- <div class="font-medium text-gray-600">Minit</div>
- <div class="font-medium text-gray-600">Saat</div>
- </div>
- </div>
- `;
-
- //Display the countdown in the element
- countdownElement.innerHTML = countdownHTML;
-
- //If the countdown is over, clear the timer and display a message
- if (distance < 0) {
- clearInterval(countdownTimer);
- countdownElement.innerHTML = 'Majlis berlangsung';
- }
- }, 1000); // Update every second (1000 milliseconds)
-
- document.addEventListener('DOMContentLoaded', function () {
-
- imageLoading()
- reset() // reset everrything to ensure smooth
- sessionStorage.setItem("initial-load", "true"); // will be used by click event
-
- });
-
-
- document.addEventListener('click', function () {
-
- let initLoad = sessionStorage.getItem("initial-load")
-
- // parts is intro cover
- let parts = document.getElementsByClassName("part");
- for (let part of parts) {
- part.classList.add("shadow-lg")
- }
-
- let body = document.querySelector("body");
- body.classList.remove("no-scroll");
-
- // the intro - only done once and
- if (initLoad == "true") {
- playMusic();
- sessionStorage.removeItem("initial-load")
- // delay timer to have that umpph feels my G
- setTimeout(() => {
- // smooth scroll only happen for first render
- smoothScrollBy(100, 3500);
- }, 600)
- }
-
- });
-
- function smoothScrollBy(distance, duration) {
- const start = window.pageYOffset;
- const startTime = performance.now();
-
- function scroll() {
- const now = performance.now();
- const time = Math.min(1, (now - startTime) / duration);
- const timeFunction = time * (2 - time); // Ease out effect
- window.scrollTo(0, start + timeFunction * distance);
-
- if (time < 1) {
- requestAnimationFrame(scroll);
- }
- }
-
- requestAnimationFrame(scroll);
- }
-
-
- // to ensure all images is loaded before starting animation and gimmick
- function imageLoading() {
- const images = document.querySelectorAll("img");
- let loadedCount = 0;
- const totalImages = images.length;
-
- images.forEach(image => {
- if (image.complete) {
- loadedCount++;
- } else {
- image.addEventListener("load", () => {
- loadedCount++;
- checkAllImagesLoaded();
- });
- image.addEventListener("error", () => {
- loadedCount++;
- checkAllImagesLoaded();
- });
- }
- });
-
- function checkAllImagesLoaded() {
-
- if (loadedCount === totalImages) {
- let loading = document.getElementById("loading");
- loading.remove();
- // parts is intro cover
- let parts = document.getElementsByClassName("part");
- for (let part of parts) {
- part.classList.remove("hidden")
- }
- }
- }
-
- //somehow the server work so fast, script doesn't have much time to set the load eventlistener
- //thus we check here, to ensure checkAllImagesLoaded run
- checkAllImagesLoaded();
- }
-
- function reset() {
-
- // reset to top
- let body = document.querySelector("body");
- body.classList.remove("no-scroll");
- window.scrollTo(0, 0);
-
- setTimeout(() => {
- body.classList.add("no-scroll");
- }, 400)
- }
-
- function playMusic(){
- var audioElement = document.getElementById('player');
- var hasPlayed = false;
- if (!hasPlayed) {
- console.log('play')
- var playPromise = audioElement.play();
-
- if (playPromise !== undefined) {
- playPromise.then(function() {
- // Automatic playback started!
- hasPlayed = true; // Prevent further attempts to play
- }).catch(function(error) {
- // Automatic playback failed.
- console.log('Autoplay failed: ' + error);
- });
- }
- }
- }
|