首页
最近更改
MediaWiki帮助
中文社区
模组
人物
团体
群聊
历史
外网社区
模组
发帖交流
论坛
聊天
博客
快捷访问
分类
文件列表
上传文件
用户列表
用户通知
礼物列表
随机页面
聊天中的在线用户
系统消息
讨论
查看源代码
查看历史
刷新
创建账号
登录
查看“︁MediaWiki:Common.js”︁的源代码
来自Age Of History 2 Chinese Wiki
←
Common.js
跳转至:
导航
、
搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。 如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */ /* 轮播图功能 */ mw.hook('wikipage.content').add(function($content) { // 查找页面中所有轮播图 $content.find('.mw-carousel').each(function() { const $carousel = $(this); const $items = $carousel.find('.carousel-item'); const $indicators = $carousel.find('.carousel-indicators'); const $prevBtn = $carousel.find('.carousel-prev'); const $nextBtn = $carousel.find('.carousel-next'); let currentIndex = 0; const slideCount = $items.length; if (slideCount === 0) return; // 创建指示器 for (let i = 0; i < slideCount; i++) { const $indicator = $('<div class="indicator"></div>'); if (i === 0) $indicator.addClass('active'); $indicator.on('click', function() { goToSlide(i); }); $indicators.append($indicator); } // 初始化第一张幻灯片 $items.eq(0).addClass('active'); // 给每个幻灯片添加点击事件 $items.each(function() { const $item = $(this); const link = $item.data('link'); if (link && link.length > 0) { $item.css('cursor', 'pointer').on('click', function() { window.location.href = link; }); } }); // 切换到指定幻灯片 function goToSlide(index) { $items.removeClass('active'); $indicators.find('.indicator').removeClass('active'); $items.eq(index).addClass('active'); $indicators.find('.indicator').eq(index).addClass('active'); currentIndex = index; } // 上一张 function prevSlide() { const newIndex = (currentIndex - 1 + slideCount) % slideCount; goToSlide(newIndex); } // 下一张 function nextSlide() { const newIndex = (currentIndex + 1) % slideCount; goToSlide(newIndex); } // 绑定按钮事件 $prevBtn.on('click', function(e) { e.preventDefault(); e.stopPropagation(); prevSlide(); }); $nextBtn.on('click', function(e) { e.preventDefault(); e.stopPropagation(); nextSlide(); }); // 自动播放 let autoplayInterval = setInterval(nextSlide, 5000); $carousel.on('mouseenter', function() { clearInterval(autoplayInterval); }).on('mouseleave', function() { autoplayInterval = setInterval(nextSlide, 5000); }); // 触摸滑动支持 let touchStartX = 0; let touchEndX = 0; $carousel.on('touchstart', function(e) { touchStartX = e.originalEvent.touches[0].clientX; }); $carousel.on('touchend', function(e) { touchEndX = e.originalEvent.changedTouches[0].clientX; // 判断滑动方向 if (touchEndX < touchStartX - 50) { nextSlide(); // 左滑,下一张 } else if (touchEndX > touchStartX + 50) { prevSlide(); // 右滑,上一张 } }); }); });
返回
Common.js
。
工具
链入页面
相关更改
特殊页面
页面信息
Cargo数据