「MediaWiki:Mobile.js」の版間の差分

編集の要約なし
編集の要約なし
タグ: 手動差し戻し 差し戻し済み モバイル編集 モバイルウェブ編集
編集の要約なし
タグ: 差し戻し済み モバイル編集 モバイルウェブ編集
48行目: 48行目:


/*メニューバー*/
/*メニューバー*/
var lastScrollTop = 0;
document.addEventListener("DOMContentLoaded", function() {
var menuBar = document.getElementById("mobileMenuBar");
    var lastScrollTop = 0; // 最後のスクロール位置を保持する変数
    var mobileMenuBar = document.getElementById('mobileMenuBar'); // mobileMenuBar要素を取得


 
    window.addEventListener("scroll", function() {
window.addEventListener("scroll", function(){
        var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
  var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
        if (currentScroll > lastScrollTop) {
 
            // 下にスクロールした時、mobileMenuBarを表示
  if (currentScroll > lastScrollTop){
            mobileMenuBar.style.display = 'block';
      // 下にスクロールしているとき
        } else {
      if (currentScroll > 100) {
            // 上にスクロールした時、mobileMenuBarを非表示にする
      menuBar.style.display = 'block';
            // ただし、ページの最上部にいる場合は表示しない
      menuBar.style.position = 'fixed'; // スクロール時には固定
            if (currentScroll <= 0) {
      menuBar.style.top = '0px';
                mobileMenuBar.style.display = 'none';
      }
            }
  } else {
        }
      // 上にスクロールしているとき
        lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // 負の値を防ぐ
      if (currentScroll <= 0) {
    }, false);
          // ページの一番上にいるとき
});
          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);
// TOPへ