$(document).ready(function () { const loadingScreen = $(".loading-screen"); // 初回トップページ用 const loadingScreenSub = $(".loading-screen_sub"); // 2回目以降のトップページ・サブページ用 const loadingCharacter = $("#loadingCharacter"); // まばたきアニメーション対象 const wrap = $(".wrap"); const gifImage = $(".loading-video img"); const gifDuration = 3000; // GIFの再生時間(ミリ秒) function disableScroll() { $("body").css("overflow", "hidden"); } function enableScroll() { $("body").css("overflow", "auto"); } function setRandomBgColor() { const colors = ["#fa1eaa", "#00cdff", "#a52dff"]; const randomColor = colors[Math.floor(Math.random() * colors.length)]; loadingScreenSub.css("background-color", randomColor); } function blinkAnimation() { setTimeout(() => { loadingCharacter.attr("src", "images/logo_close_w.svg"); }, 200); setTimeout(() => { loadingCharacter.attr("src", "images/logo_open_w.svg"); }, 350); setTimeout(() => { loadingCharacter.attr("src", "images/logo_close_w.svg"); }, 500); setTimeout(() => { loadingCharacter.attr("src", "images/logo_open_w.svg"); }, 650); setTimeout(blinkAnimation, 2000); } function getTodayString() { const today = new Date(); return `${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}`; } const today = getTodayString(); const lastPlayedDate = localStorage.getItem("loadingPlayedDate"); disableScroll(); if (lastPlayedDate !== today) { // **今日初めての訪問 → GIFローディング** loadingScreen.show(); loadingScreenSub.hide(); setTimeout(() => { gifImage.attr("src", "images/moving_logo_last_frame.png"); loadingScreen.fadeOut(1000, function () { wrap.fadeIn(500); enableScroll(); }); localStorage.setItem("loadingPlayedDate", today); // 日付を保存 }, gifDuration); } else { // **今日2回目以降の訪問 → サブページ用ローディング** loadingScreen.hide(); loadingScreenSub.show(); setRandomBgColor(); blinkAnimation(); setTimeout(() => { loadingScreenSub.fadeOut(500, function () { enableScroll(); }); }, 1000); } setTimeout(enableScroll, 5000); // 念のためスクロール許可 });