226
回編集
編集の要約なし タグ: 差し戻し済み モバイル編集 モバイルウェブ編集 |
編集の要約なし タグ: 手動差し戻し 差し戻し済み モバイル編集 モバイルウェブ編集 |
||
47行目: | 47行目: | ||
}; | }; | ||
/* メニューバー */ | /*メニューバー*/ | ||
var lastScrollTop = 0; | var lastScrollTop = 0; | ||
var menuBar = document.getElementById("mobileMenuBar"); | var menuBar = document.getElementById("mobileMenuBar"); | ||
window.addEventListener("scroll", function() { | window.addEventListener("scroll", function(){ | ||
var currentScroll = window.pageYOffset || document.documentElement.scrollTop; | |||
if (currentScroll > lastScrollTop){ | |||
// 下にスクロールしているとき | |||
if (currentScroll > 100) { | |||
menuBar.style.display = 'block'; | |||
menuBar.style.position = 'fixed'; // スクロール時には固定 | |||
menuBar.style.top = '0px'; | |||
} | |||
} else { | |||
// 上にスクロールしているとき | |||
if (currentScroll <= 0) { | |||
// ページの一番上にいるとき | |||
menuBar.style.display = 'none'; | |||
} else if (currentScroll > 100) { | |||
menuBar.style.display = 'block'; | |||
menuBar.style.position = 'fixed'; // スクロール時には固定 | |||
menuBar.style.top = '0px'; | |||
} | |||
} | |||
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // ネガティブな値を防ぐ | |||
}, false); | }, false); | ||
// TOPへ |