MediaWiki:Mobile.js

提供:パルワールド 攻略Wiki
2024年1月15日 (月) 23:15時点における管理人 (トーク | 投稿記録)による版
移動先:案内検索

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer / Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: Ctrl-F5を押してください
//トップに戻るボタン
$(document).ready(function() {
    var backToTopButton = $('<div/>', {
        id: 'back-to-top',
        html: '<i class="fa-solid fa-chevron-up"></i>',
        click: function() {
            window.scrollTo(0, 0);
        }
    }).appendTo('body');

    backToTopButton.show();

    var inactivityTimer;

    function resetInactivityTimer() {
        backToTopButton.show();
        clearTimeout(inactivityTimer);
        inactivityTimer = setTimeout(function() {
            backToTopButton.fadeOut();
        }, 2000);
    }

    $(window).scroll(resetInactivityTimer);
    $(window).mousemove(resetInactivityTimer);

    resetInactivityTimer();
});
//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';
    }
};

/*メニューバー*/
document.addEventListener("DOMContentLoaded", function() {
    // 初期状態ではmobileMenuBarを非表示に設定
    var mobileMenuBar = document.getElementById('mobileMenuBar');
    mobileMenuBar.style.display = 'none';

    // スクロールイベントリスナー
    window.addEventListener('scroll', function() {
        // ページの最上部からのスクロール距離を取得
        var scrollDistance = window.scrollY;

        if (scrollDistance > 100) {
            // 100px以上スクロールした場合、mobileMenuBarを表示
            mobileMenuBar.style.display = 'block';
        } else {
            // 100px未満に戻った場合、mobileMenuBarを非表示
            mobileMenuBar.style.display = 'none';
        }
    });
});
Copyright © 2003-2024 ヘイグ All Rights Reserved.