此处公告通常对读者进行申明或对该WIKI某些规则进行公告,请在确认后修改本通告。本WIKI编辑权限开放,欢迎收藏起来防止迷路,也希望有爱的小伙伴和我们一起编辑哟~

全站通知:

帮助:Swiper

来自魔塔WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模板为一键安装导入,不建议手动修改。

模板

在此期间没有符合这些条件的编辑

简单说明

版本:1.0

说明:轮播展示图片或内容。


使用说明

{{Swiper
|翻页=     <!-- 可省略,可选值:箭头 -->
|分页=是   <!-- 可省略,默认值:是,可选值:是/否 -->
|效果=slide <!-- 可省略,默认值:slide,可选值:slide/fade/creative/... -->
|循环=是   <!-- 可省略,默认值:是,可选值:是/否。当仅有一张图时不循环。 -->
|自动播放=是<!-- 可省略,默认值:是,可选值:是/否。当仅有一张图时不自动播放。 -->
|延迟=2500  <!-- 可省略,默认值:2500,为毫秒数 -->
|联动=     <!-- 无联动时可省略,有联动时必填,可选值:主图/缩略图 -->
|额外参数=  <!-- 可省略,仅当有特殊需求时写入 -->
|id=mySwiper<!-- 可省略,为轮播图id -->
|[[File:预置banner1.jpg]]
|[[File:预置banner2.jpg]]
|[[File:预置banner1.jpg]]
|[[File:预置banner2.jpg]]
|[[File:预置banner1.jpg]]
}}

示例

'"`UNIQ--esc-00000003-QINU`"'
\n\{\{Swiper\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\}\}\n


'"`UNIQ--esc-00000007-QINU`"'
\n\{\{Swiper\n\!翻页\e箭头\n\!分页\e否\n\!效果\efade\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\}\}\n


'"`UNIQ--esc-0000000B-QINU`"'
\n\{\{Swiper\n\!联动\e主图\n\!自动播放\e否\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\}\}\n\{\{Swiper\n\!联动\e缩略图\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\!\(\(File:预置banner2.jpg\)\)\n\!\(\(File:预置banner1.jpg\)\)\n\}\}\n


'"`UNIQ--esc-0000000F-QINU`"'
\n\{\{Swiper\n\!联动\e缩略图\n\!\ldiv\g红色\l/div\g\n\!\ldiv\g黄色\l/div\g\n\}\}\n\{\{Swiper\n\!翻页\e箭头\n\!联动\e主图\n\!效果\ecreative\n\!延迟\e5000\n\!额外参数\ecreativeEffect:\{prev:\{translate:\(0,0,-400\),\},next:\{translate:\('100%',0,0\)\}\_\}\n\!1\e\ldiv\_style\e"width:100%;height:100px;background:#e7bfbf;"\g这是红色\l/div\g\n\!2\e\ldiv\_style\e"width:100%;height:100px;background:#e7d4bf;"\g这是黄色\l/div\g\n\}\}\n


'"`UNIQ--esc-00000013-QINU`"'
\n\{\{Swiper\n\!1\e\ldiv\_style\e"width:100%;height:100px;background:#e7bfbf;"\g这是红色\l/div\g\n\}\}\n


作者

作者:迦洛翎

依赖

<link rel="stylesheet" href="//wiki-dev-patch-oss.oss-cn-hangzhou.aliyuncs.com/test/swiper-bundle.css"> <script src="//wiki-dev-patch-oss.oss-cn-hangzhou.aliyuncs.com/test/swiper-bundle.min.js"></script> <script> RLQ.push(['jquery', () => { $(function(){ const swipers = []; Object.assign(mw.bwiki = mw.bwiki || {}, {swipers: swipers}); function parseOptions(input, el) { let index = 0; const references = [ // 白名单按「长字符串优先」排列:startsWith 为前缀匹配, // 短串排前会先命中并留下尾巴(如 ...[0] 命中后剩 .swiper),导致「存在多余内容」。 // godsoul:带空值保护的包装写法,整体以 '(' 开头,必须整条匹配 ['($(el).parent().find(".bwiki-swiper-thumbs")[0] || {}).swiper', () => $(el).parent().find('.bwiki-swiper-thumbs')[0]?.swiper], ['$(el).parent().find(".bwiki-swiper-thumbs")[0].swiper', () => $(el).parent().find('.bwiki-swiper-thumbs')[0]?.swiper], // ssjj2:缩略图侧用 .bwiki-swiper 反向引用主图;语义与原 eval 完全一致 ['$(el).parent().find(".bwiki-swiper")[0].swiper', () => $(el).parent().find('.bwiki-swiper')[0]?.swiper], ['$(el).find(".swiper-button-next")[0]', () => $(el).find('.swiper-button-next')[0]], ['$(el).find(".swiper-button-prev")[0]', () => $(el).find('.swiper-button-prev')[0]], ['$(el).find(".swiper-pagination")[0]', () => $(el).find('.swiper-pagination')[0]] ]; function fail(message) { throw new Error(`Swiper 参数: ${message}(位置 ${index})`); } function space() { while (/\s/.test(input[index] || '')) index++; } function expect(char) { space(); if (input[index] !== char) fail(`需要 ${char}`); index++; } function identifier() { space(); const match = /^[A-Za-z_$][\w$-]*/.exec(input.slice(index)); if (!match) fail('需要标识符'); index += match[0].length; return match[0]; } function string() { space(); const quote = input[index++]; let result = ''; while (index < input.length) { let char = input[index++]; if (char === quote) return result; if (char === '\n' || char === '\r') fail('字符串未闭合'); if (char !== '\\') { result += char; continue; } char = input[index++]; if (char === 'u' || char === 'x') { const length = char === 'u' ? 4 : 2; const hex = input.slice(index, index + length); if (!new RegExp(`^[0-9A-Fa-f]{${length}}$`).test(hex)) fail('无效字符转义'); result += String.fromCharCode(parseInt(hex, 16)); index += length; } else { const escapes = {n:'\n', r:'\r', t:'\t', b:'\b', f:'\f', v:'\v'}; result += Object.hasOwn(escapes, char) ? escapes[char] : char; } } fail('字符串未闭合'); } function object() { const result = {}; expect('{'); space(); if (input[index] === '}') { index++; return result; } while (index < input.length) { space(); const key = input[index] === '"' || input[index] === "'" ? string() : identifier(); if (['__proto__', 'prototype', 'constructor'].includes(key)) fail('不允许的属性名'); expect(':'); result[key] = value(); space(); if (input[index] === '}') { index++; return result; } expect(','); space(); if (input[index] === '}') { index++; return result; } } fail('对象未闭合'); } function array() { const result = []; expect('['); space(); if (input[index] === ']') { index++; return result; } while (index < input.length) { result.push(value()); space(); if (input[index] === ']') { index++; return result; } expect(','); space(); if (input[index] === ']') { index++; return result; } } fail('数组未闭合'); } function value() { space(); for (const [source, resolve] of references) { if (input.startsWith(source, index)) { index += source.length; return resolve(); } } const char = input[index]; if (char === '{') return object(); if (char === '[') return array(); if (char === '"' || char === "'") return string(); const number = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/.exec(input.slice(index)); if (number) { index += number[0].length; return Number(number[0]); } const word = identifier(); if (word === 'true') return true; if (word === 'false') return false; if (word === 'null') return null; fail(`不允许的值 ${word}`); } const result = value(); space(); if (index !== input.length) fail('存在多余内容'); if (!result || Array.isArray(result) || typeof result !== 'object') fail('顶层必须是对象'); return result; } $.each($(".bwiki-swiper-thumbs").get().concat($(".bwiki-swiper:not('.bwiki-swiper-thumbs')").get()), function (i, el) { const attrs = this.attributes; const options = {}; $.each(attrs, function (i, attr) { if (attr.nodeName.indexOf("data-swiper-") === -1 || attr.nodeName === "data-swiper-options") return true; options[attr.nodeName.replace("data-swiper-", "")] = attr.nodeValue; }); try { const encoded = $(this).attr("data-swiper-options") || "%7B%7D"; const legacy = decodeURIComponent(encoded).replace(/\n|\t/g, "").replace(/\+/g, " "); $.extend(options, parseOptions(legacy, el)); } catch (e) { console.error(e); } console.log("swiper-options", options); swipers.push(new Swiper($.extend({el:this}, options))); }) }) }]); </script>
  • 预置banner1.jpg
  • 预置banner2.jpg
  • 预置banner1.jpg
  • 预置banner2.jpg
  • 预置banner1.jpg
基于MsUpload的文件上传
基于MsUpload的文件上传
基于MsUpload的文件上传
基于MsUpload的文件上传
基于MsUpload的文件上传

更新日志

  • 1.0 基本完成
  • 1.1 修复移动端点击箭头后出现边框的问题
  • 1.2 优化仅有一张图时关闭自动播放