「MediaWiki:Mobile.js」の版間の差分
提供:パルワールド 攻略Wiki
編集の要約なし タグ: 手動差し戻し 差し戻し済み モバイル編集 モバイルウェブ編集 |
編集の要約なし タグ: 差し戻し済み モバイル編集 モバイルウェブ編集 |
||
48行目: | 48行目: | ||
/*メニューバー*/ | /*メニューバー*/ | ||
var lastScrollTop = 0; | document.addEventListener("DOMContentLoaded", function() { | ||
var | var lastScrollTop = 0; // 最後のスクロール位置を保持する変数 | ||
var mobileMenuBar = document.getElementById('mobileMenuBar'); // mobileMenuBar要素を取得 | |||
window.addEventListener("scroll", function() { | |||
window.addEventListener("scroll", function(){ | var currentScroll = window.pageYOffset || document.documentElement.scrollTop; | ||
if (currentScroll > lastScrollTop) { | |||
// 下にスクロールした時、mobileMenuBarを表示 | |||
mobileMenuBar.style.display = 'block'; | |||
} else { | |||
// 上にスクロールした時、mobileMenuBarを非表示にする | |||
// ただし、ページの最上部にいる場合は表示しない | |||
if (currentScroll <= 0) { | |||
mobileMenuBar.style.display = 'none'; | |||
} | |||
} | |||
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // 負の値を防ぐ | |||
}, false); | |||
}); | |||
}, false); | |||
2024年1月15日 (月) 23:05時点における版
//トップに戻るボタン
$(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() {
var lastScrollTop = 0; // 最後のスクロール位置を保持する変数
var mobileMenuBar = document.getElementById('mobileMenuBar'); // mobileMenuBar要素を取得
window.addEventListener("scroll", function() {
var currentScroll = window.pageYOffset || document.documentElement.scrollTop;
if (currentScroll > lastScrollTop) {
// 下にスクロールした時、mobileMenuBarを表示
mobileMenuBar.style.display = 'block';
} else {
// 上にスクロールした時、mobileMenuBarを非表示にする
// ただし、ページの最上部にいる場合は表示しない
if (currentScroll <= 0) {
mobileMenuBar.style.display = 'none';
}
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // 負の値を防ぐ
}, false);
});