Widget:GameSwitcher:修订间差异
来自OGAS数据中枢
更多操作
无编辑摘要 |
无编辑摘要 标签:手工回退 |
||
| (未显示同一用户的6个中间版本) | |||
| 第1行: | 第1行: | ||
<noinclude> | <noinclude> | ||
少女前线系列多游戏首页切换Widget。调用方式:<code><nowiki>{{#widget:GameSwitcher}}</nowiki></code> | |||
</noinclude><includeonly><script> | </noinclude><includeonly><script> | ||
( function () { | ( function () { | ||
| 第47行: | 第46行: | ||
} | } | ||
function moveIndicator( tab ) { | |||
var indicator = document.getElementById( 'gf-tab-indicator' ); | |||
if ( !indicator ) { return; } | |||
indicator.style.width = tab.offsetWidth + 'px'; | |||
indicator.style.transform = 'translateX(' + tab.offsetLeft + 'px)'; | |||
} | |||
var currentGame = 'gf'; | var currentGame = 'gf'; | ||
var switching = false; | var switching = false; | ||
var pending = null; | |||
function doSwitch( game, tabEl ) { | |||
var slides = document.querySelectorAll( '#gf-homepage .gf-hero-slide' ); | var slides = document.querySelectorAll( '#gf-homepage .gf-hero-slide' ); | ||
var panels = document.querySelectorAll( '#gf-homepage .gf-content-panel' ); | var panels = document.querySelectorAll( '#gf-homepage .gf-content-panel' ); | ||
| 第72行: | 第65行: | ||
var inSlide = document.getElementById( 'hero-' + game ); | var inSlide = document.getElementById( 'hero-' + game ); | ||
if ( inSlide ) { | if ( inSlide ) { | ||
inSlide.style.zIndex = '1'; | inSlide.style.zIndex = '1'; | ||
| 第95行: | 第74行: | ||
} | } | ||
tabs.forEach( function ( t ) { | tabs.forEach( function ( t ) { | ||
var on = t.getAttribute( 'data-game' ) === game; | var on = t.getAttribute( 'data-game' ) === game; | ||
| 第101行: | 第79行: | ||
t.setAttribute( 'aria-selected', on ? 'true' : 'false' ); | t.setAttribute( 'aria-selected', on ? 'true' : 'false' ); | ||
} ); | } ); | ||
if ( tabEl ) { moveIndicator( tabEl ); } | if ( tabEl ) { moveIndicator( tabEl ); } | ||
panels.forEach( function ( p ) { | panels.forEach( function ( p ) { | ||
p.classList.toggle( 'active', p.id === 'content-' + game ); | p.classList.toggle( 'active', p.id === 'content-' + game ); | ||
} ); | } ); | ||
currentGame = game; | |||
switching = true; | |||
setTimeout( function () { | setTimeout( function () { | ||
slides.forEach( function ( s ) { | slides.forEach( function ( s ) { s.style.zIndex = ''; } ); | ||
switching = false; | |||
if ( pending && pending.game !== currentGame ) { | |||
var p = pending; | |||
pending = null; | |||
doSwitch( p.game, p.tabEl ); | |||
} else { | |||
pending = null; | |||
} | |||
}, 520 ); | |||
} | |||
function switchGame( game, tabEl ) { | |||
if ( game === currentGame ) { return; } | |||
if ( switching ) { | |||
pending = { game: game, tabEl: tabEl }; | |||
var tabs = document.querySelectorAll( '#gf-homepage .gf-tab' ); | |||
tabs.forEach( function ( t ) { | |||
var on = t.getAttribute( 'data-game' ) === game; | |||
t.classList.toggle( 'active', on ); | |||
t.setAttribute( 'aria-selected', on ? 'true' : 'false' ); | |||
} ); | } ); | ||
if ( tabEl ) { moveIndicator( tabEl ); } | |||
return; | |||
}, | } | ||
doSwitch( game, tabEl ); | |||
} | } | ||
| 第123行: | 第121行: | ||
if ( !tabs.length ) { return; } | if ( !tabs.length ) { return; } | ||
Object.keys( heroImages ).forEach( function ( game ) { | Object.keys( heroImages ).forEach( function ( game ) { | ||
getWikiImageUrl( heroImages[ game ], function ( url ) { | getWikiImageUrl( heroImages[ game ], function ( url ) { | ||
var bg = document.getElementById( 'hero-' + game + '-bg' ); | var bg = document.getElementById( 'hero-' + game + '-bg' ); | ||
var fg = document.getElementById( 'hero-' + game + '-fg' ); | var fg = document.getElementById( 'hero-' + game + '-fg' ); | ||
var val = 'url("' + url + '")'; | var val = 'url("' + url + '")'; | ||
if ( bg ) { bg.style.backgroundImage = val; } | if ( bg ) { bg.style.backgroundImage = val; } | ||
| 第136行: | 第133行: | ||
applyFadeColor(); | applyFadeColor(); | ||
var firstActive = document.querySelector( '#gf-homepage .gf-tab.active' ); | var firstActive = document.querySelector( '#gf-homepage .gf-tab.active' ); | ||
if ( firstActive ) { | if ( firstActive ) { | ||
setTimeout( function () { moveIndicator( firstActive ); }, 50 ); | setTimeout( function () { moveIndicator( firstActive ); }, 50 ); | ||
} | } | ||
| 第155行: | 第150行: | ||
} ); | } ); | ||
window.addEventListener( 'resize', function () { | window.addEventListener( 'resize', function () { | ||
var active = document.querySelector( '#gf-homepage .gf-tab.active' ); | var active = document.querySelector( '#gf-homepage .gf-tab.active' ); | ||
2026年6月20日 (六) 23:23的最新版本
少女前线系列多游戏首页切换Widget。调用方式:{{#widget:GameSwitcher}}