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

編集の要約なし
編集の要約なし
タグ: 差し戻し済み モバイル編集 モバイルウェブ編集
編集の要約なし
タグ: 差し戻し済み モバイル編集 モバイルウェブ編集
27行目: 27行目:
});
});
//Menu
//Menu
/*mobilemenu*/
function isMobileDevice() {
    const userAgent = navigator.userAgent;
    const screenWidth = window.innerWidth;
    // モバイルデバイスのユーザーエージェントをチェック(iPadを除外)
    const isMobileUA = /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent) && !/iPad/i.test(userAgent);
    // 画面サイズが特定の最大幅(例えば768px)以下かどうかをチェック
    const isSmallScreen = screenWidth <= 768;
    // 両方の条件を満たす場合にtrueを返す
    return isMobileUA && isSmallScreen;
}
window.onload = function() {
    if (isMobileDevice()) {
        document.getElementById('mobileMenuBar').style.display = 'block';
    }
};


/*メニューバー*/
/*メニューバー*/
55行目: 36行目:
     // スクロールイベントリスナー
     // スクロールイベントリスナー
     window.addEventListener('scroll', function() {
     window.addEventListener('scroll', function() {
         // ページの最上部からのスクロール距離を取得
         // モバイルデバイスでの表示をチェック(例:幅が768px以下)
        var scrollDistance = window.scrollY;
        if (window.innerWidth <= 768) {
            // ページの最上部からのスクロール距離を取得
            var scrollDistance = window.scrollY;


        if (scrollDistance > 100) {
            if (scrollDistance > 100) {
            // 100px以上スクロールした場合、mobileMenuBarを表示
                // 100px以上スクロールした場合、mobileMenuBarを表示
             mobileMenuBar.style.display = 'block';
                mobileMenuBar.style.display = 'block';
             } else {
                // 100px未満に戻った場合、mobileMenuBarを非表示
                mobileMenuBar.style.display = 'none';
            }
         } else {
         } else {
             // 100px未満に戻った場合、mobileMenuBarを非表示
             // モバイルデバイスでない場合、常に非表示
            mobileMenuBar.style.display = 'none';
        }
    });
 
    // ウィンドウのサイズ変更時にもチェック
    window.addEventListener('resize', function() {
        if (window.innerWidth > 768) {
             mobileMenuBar.style.display = 'none';
             mobileMenuBar.style.display = 'none';
         }
         }
     });
     });
});
});