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

提供:パルワールド 攻略Wiki
移動先:案内検索
編集の要約なし
タグ: 差し戻し済み モバイル編集 モバイルウェブ編集
編集の要約なし
タグ: 差し戻し済み モバイル編集 モバイルウェブ編集
50行目: 50行目:
var lastScrollTop = 0;
var lastScrollTop = 0;
var menuBar = document.getElementById("mobileMenuBar");
var menuBar = document.getElementById("mobileMenuBar");
var headerMenu = document.getElementById("headerMenu"); // 本来のheadermenuのIDを仮定しています
// 初期状態で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が画面から消えたかどうかをチェック
    var headerMenuBottom = headerMenu.offsetTop + headerMenu.offsetHeight;
    var isHeaderMenuVisible = headerMenuBottom > currentScroll;


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

2024年1月15日 (月) 22:25時点における版

//トップに戻るボタン
$(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';
    }
};

/* メニューバー */
var lastScrollTop = 0;
var menuBar = document.getElementById("mobileMenuBar");
var headerMenu = document.getElementById("headerMenu"); // 本来のheadermenuのIDを仮定しています

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

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

    // headerMenuが画面から消えたかどうかをチェック
    var headerMenuBottom = headerMenu.offsetTop + headerMenu.offsetHeight;
    var isHeaderMenuVisible = headerMenuBottom > currentScroll;

    if (currentScroll > lastScrollTop) {
        // 下にスクロールしているとき
        if (!isHeaderMenuVisible) {
            // headerMenuが見えなくなったらmobileMenuBarを表示
            menuBar.style.display = 'block';
            menuBar.style.position = 'fixed';
            menuBar.style.top = '0px';
        }
    } else {
        // 上にスクロールしているとき
        if (isHeaderMenuVisible) {
            // headerMenuが見える場合はmobileMenuBarを非表示
            menuBar.style.display = 'none';
        }
    }
    lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);
Copyright © 2003-2024 ヘイグ All Rights Reserved.