$(function() {
//---------------------------------------------
// 閲覧セクションによってナビゲーションの色を変える
//---------------------------------------------
$(document).ready(function() {
$(window).on("scroll load", function() {
const sections = $("section"); // Get all sections
sections.each(function() {
const rect = this.getBoundingClientRect();
// Calculate the middle of the section to consider it as "in view"
const middle = (rect.top + rect.bottom) / 2;
// If section is in view, update navigation color
if (middle >= 0 && middle <= window.innerHeight) {
const sectionId = $(this).attr("id"); // Get section ID
const navLink = $(`.nav li.${sectionId} a`); // Find corresponding nav link
// Reset all nav links to default state
$(".nav li a").removeClass("active");
// Add active class to the current nav link
navLink.addClass("active");
}
});
});
});
//---------------------------------------------
//ローディングアニメーション
//---------------------------------------------
var loader = $('.loader-wrap');
//ページの読み込みが完了したらアニメーションを非表示
$(window).on('load',function(){
loader.fadeOut();
$('body').removeClass('js-no-scroll');
});
//ページの読み込みが完了してなくても3秒後にアニメーションを非表示にする
setTimeout(function(){
loader.fadeOut();
},3000);
//---------------------------------------------
// ハンバーガーメニュー
//---------------------------------------------
$(document).ready(function() {
$(".toggle").click(function() {
$(this).toggleClass("active"); // ボタンのアイコンをアクティブに切り替える
$(".sidebar").toggleClass("show"); // サイドバー(メニュー)の表示・非表示を切り替える
});
//ページ内リンククリック時にハンバーガーメニューを閉じる
$('.sidebar a[href]').on('click', function() {
$('.toggle').trigger('click');
});
//---------------------------------------------
// ハンバーガーメニューが開いている時はサイトをスクロールさせない
//---------------------------------------------
// $('.toggle').click(function() {
// $('body').toggleClass("active");
// });
//---------------------------------------------
// SP閲覧時のみ電話番号にリンクを付ける
//---------------------------------------------
var ua = navigator.userAgent;
if(ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0){
$('.tel-link').each(function(){
var str = $(this).text();
$(this).html($('').attr('href', 'tel:' + str.replace(/-/g, '')).append(str + ''));
});
}
//---------------------------------------------
// 外部リンクを別ウィンドウで開く
//---------------------------------------------
$('a[href^=https]').not('[href*="'+location.hostname+'"]').attr('target', '_blank');
$('a[href^=http]').not('[href*="'+location.hostname+'"]').attr('target', '_blank');
//---------------------------------------------
// スムーズスクロール
//---------------------------------------------
//#を含むリンクが対象
$('a[href^="#"]').click(function(){
var speed = 600,
href = $(this).attr("href"),
//href="#"ならページトップ(html)へ href="#"以外ならhrefの指定先へ
target = $(href == "#" || href=="" ? 'html':href),
position = target.offset().top;
$('body,html').animate({scrollTop:position},speed,'swing');
return false;
});
//---------------------------------------------
// pagetopボタン スクロールでフェードイン
//---------------------------------------------
// 300pxスクロールしたらpagetopボタンを表示する
var topBtn=$('#PageTop');
topBtn.hide();
$(window).scroll(function() {
if($(this).scrollTop() > 300){
topBtn.fadeIn();
} else {
topBtn.fadeOut();
}
});
//---------------------------------------------
// スクロールで要素を表示
//---------------------------------------------
function showElementAnimation() {
var element = document.getElementsByClassName('js-animation');
if(!element) return; // 要素がなかったら処理をキャンセル
var showTiming = window.innerHeight > 768 ? 200 : 40; // 要素が出てくるタイミングはここで調整
var scrollY = window.pageYOffset;
var windowH = window.innerHeight;
for(var i=0;i elemY) {
element[i].classList.add('is-show');
} else if(scrollY + windowH < elemY) {
// 上にスクロールして再度非表示にする場合はこちらを記述
element[i].classList.remove('is-show');
}
}
}
showElementAnimation();
window.addEventListener('scroll', showElementAnimation);
});
var stroke;
stroke = new Vivus('mask', {//アニメーションをするIDの指定
start:'manual',//自動再生をせずスタートをマニュアルに
type: 'scenario-sync',// アニメーションのタイプを設定
duration: 1.5,//アニメーションの時間設定。数字が小さくなるほど速い
forceRender: false,//パスが更新された場合に再レンダリングさせない
animTimingFunction:Vivus.EASE,//動きの加速減速設定
},
function(){
$("#mask").attr("class", "done");//描画が終わったらdoneというクラスを追加
}
);
$(window).on('load',function(){
$("#splash").delay(3000).fadeOut('slow');//ローディング画面を3秒(3000ms)待機してからフェイドアウト
$("#splash_logo").delay(3000).fadeOut('slow');//ロゴを3秒(3000ms)待機してからフェイドアウト
stroke.play();//SVGアニメーションの実行
});
});