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

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


/* メニューバー */
/*メニューバー*/
// メニューバー
var lastScrollTop = 0;
var lastScrollTop = 0;
var menuBar = document.getElementById("mobileMenuBar");
var menuBar = document.getElementById("mobileMenuBar");
var headerMenu = document.querySelector(".header-container.header-chrome"); // 本来のheadermenu


// 初期状態でmobileMenuBarを非表示にする
menuBar.style.display = 'none';


window.addEventListener("scroll", function() {
window.addEventListener("scroll", function(){
    var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
  var currentScroll = window.pageYOffset || document.documentElement.scrollTop;


    // headerMenuが画面から消えたかどうかをチェック
  if (currentScroll > lastScrollTop){
    var headerMenuBottom = headerMenu.offsetTop + headerMenu.offsetHeight;
      // 下にスクロールしているとき
    var isHeaderMenuVisible = headerMenuBottom > currentScroll;
      if (currentScroll > 100) {
 
      menuBar.style.display = 'block';
    if (!isHeaderMenuVisible) {
      menuBar.style.position = 'fixed'; // スクロール時には固定
        // headerMenuが見えなくなったらmobileMenuBarを表示
      menuBar.style.top = '0px';
        menuBar.style.display = 'block';
      }
        menuBar.style.position = 'fixed';
  } else {
        menuBar.style.top = '0px';
      // 上にスクロールしているとき
    } else {
      if (currentScroll <= 0) {
        // headerMenuが見える場合はmobileMenuBarを非表示
          // ページの一番上にいるとき
        menuBar.style.display = 'none';
          menuBar.style.display = 'none';
    }
      } else if (currentScroll > 100) {
   
          menuBar.style.display = 'block';
    lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
          menuBar.style.position = 'fixed'; // スクロール時には固定
          menuBar.style.top = '0px';
      }
  }
  lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // ネガティブな値を防ぐ
}, false);
}, false);
// TOPへ