微件:GameSwitcher
来自OGAS数据中枢
更多操作
本Widget为少女前线系列多游戏首页提供切换交互逻辑。
不接受参数,直接在首页调用:{{#widget:GFHomepageSwitcher}}
<script>
(function () {
'use strict';
function init() {
var tabs = document.querySelectorAll('#gf-homepage .gf-tab');
var heroSlides = document.querySelectorAll('#gf-homepage .gf-hero-slide');
var contentPanels = document.querySelectorAll('#gf-homepage .gf-content-panel');
if (!tabs.length) return;
tabs.forEach(function (tab) {
tab.addEventListener('click', function () {
var game = this.getAttribute('data-game');
tabs.forEach(function (t) {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
});
this.classList.add('active');
this.setAttribute('aria-selected', 'true');
heroSlides.forEach(function (s) {
s.classList.remove('active');
if (s.id === 'hero-' + game) {
s.classList.add('active');
}
});
contentPanels.forEach(function (p) {
p.classList.remove('active');
if (p.id === 'content-' + game) {
p.classList.add('active');
}
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})(); </script>