Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Template:Gallery: Difference between revisions

Template page
No edit summary
No edit summary
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly><ul class="template gallery" {{#if:{{{perrow|}}}|style="width:{{#expr:({{#rmatch:{{{width|150px}}}|(\d+)|$1}}+10)*{{{perrow}}}}}px"}}>
{{#vardefine:uniqueClass|gallery-{{#timeseq:}}}}
{{#if:{{{caption|}}}|<li class="gallerycaption">{{{caption}}}</li>}}
<ul class="{{#var:uniqueClass}}" {{#if:{{{perrow|}}}|style="max-width:{{#expr:({{#rmatch:{{{width|150px}}}|(\d+)|$1}}+10)*{{{perrow}}}}px;"}}>
{{#forargs:|k|v|{{#rmatch:{{#var:k}}|^\d+$|{{#ifeq:{{#expr:{{#var:k}} mod 2}}|1|<li class="gallerybox"><div class="thumb" style="width:{{{width|150px}}};height:{{{height|150px}}};">[[{{#var:v}}]]</div><div class="gallerytext"><p>|{{#var:v}}</p></div></li>}}}}}}
  {{#if:{{{caption|}}}|<li class="gallerycaption">{{{caption}}}</li>}}
</ul>{{#if:{{#varexists:gallery}}||{{#vardefineecho:gallery
  {{#forargs:|k|v|{{#rmatch:{{#var:k}}|^\d+$|{{#ifeq:{{#expr:{{#var:k}} mod 2}}|1|<li class="gallerybox"><div class="thumb">[[{{#var:v}}]]</div><div class="gallerytext"><p>|{{#var:v}}</p></div></li>}}}}}}
|{{#css:
</ul>
ul.gallery.template{
<style>
     margin:2px;padding:2px;
ul.{{#var:uniqueClass}} { margin: 2px; padding: 2px; }
ul.{{#var:uniqueClass}} li.gallerycaption { font-weight: bold; text-align: center; word-wrap: break-word; }
ul.{{#var:uniqueClass}} li.gallerybox { vertical-align: top; display: inline-flex; flex-direction: column; }
ul.{{#var:uniqueClass}} li.gallerybox div.thumb {  
     width: {{{width|150px}}};
    height: {{{height|150px}}};
    max-width: {{{width|150px}}};
    max-height: {{{height|150px}}};  
    padding: 15px;
    border: 1px solid #c8ccd1;
    background-color: #f8f9fa;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 4px;  
}
}
ul.{{#var:uniqueClass}} li.gallerybox div.thumb img {  
ul.gallery.template li.gallerycaption{
     max-width: {{#expr:({{#rmatch:{{{width|150px}}}|(\d+)|$1}}-30)}}px;  
     font-weight:bold;text-align:center;word-wrap:break-word
    max-height: {{#expr:({{#rmatch:{{{width|150px}}}|(\d+)|$1}}-30)}}px;  
    object-fit: contain;
    margin: 0 auto;
}
}
ul.{{#var:uniqueClass}} div.gallerytext { overflow: hidden; font-size: 94%; padding: 2px 4px; word-wrap: break-word; text-align: center; }
ul.gallery.template li.gallerybox{
</style>
    vertical-align:top;display:inline-flex;flex-direction:column;
</includeonly>
}
<noinclude>
ul.gallery.template li.gallerybox div.thumb{
模板使用说明
    border:1px solid #c8ccd1;
</noinclude>
    background-color:#f8f9fa;
 
    display:flex;
 
    justify-content:center;
    align-items:center;margin:4px;
    overflow-y:hidden;
}
ul.gallery.template li.gallerybox div.thumb span a img{
    width: 100%;
    object-fit:contain;margin:0 auto;
}
ul.gallery.template div.gallerytext{
    overflow:hidden;font-size:94%;padding:2px 4px;word-wrap:break-word;text-align:center;
}  
}}}}}}</includeonly>
<noinclude>
<noinclude>
<!-- 简述模板作用 -->
<!-- 简述模板作用 -->
Line 45: Line 38:
===调用参数===
===调用参数===
<!-- 填写模板用法 -->
<!-- 填写模板用法 -->
<pre>{{gallery|id=<id>|caption=<caption>|width=<width>|height=<height>|perrow=<perrow>
<pre>{{gallery|caption=<caption>|width=<width>|height=<height>|perrow=<perrow>
|file1|title1
|file1|title1
|file2|title2
|file2|title2
Line 58: Line 51:
===选填===
===选填===
<!-- 选填参数项的说明,如没有可以留空或删除 -->
<!-- 选填参数项的说明,如没有可以留空或删除 -->
*id: gallery 当在同一个页面中需要多次调用此模板时必填
*caption:gallery的标题
*caption:gallery的标题
*width:宽(单位:px)
*width:宽(单位:px)设置宽高时建议按照图片尺寸比例设置
*height:高(单位:px)
*height:高(单位:px)设置宽高时建议按照图片尺寸比例设置
*perrow:每行显示数量
*perrow:每行显示数量
*title:图片提示文字
*title:图片提示文字
==示例1==
==示例1==
<!-- 模板使用示例 -->
<!-- 模板使用示例 -->
Line 73: Line 66:
}}</pre>
}}</pre>
===显示内容===
===显示内容===
{{gallery|id=grallery1
{{gallery
|file:Main MPI3508.jpg|文字描述
|file:Main MPI3508.jpg|文字描述
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
Line 82: Line 75:
<!-- 模板使用示例 -->
<!-- 模板使用示例 -->
===你所写的===
===你所写的===
<pre>{{gallery|id=grallery2|caption=标题|width=300px|height=200px|perrow=2
<pre>{{gallery|caption=标题|width=200px|height=200px|perrow=2
|file:Main MPI3508.jpg|文字描述
|file:Main MPI3508.jpg|文字描述
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
Line 88: Line 81:
}}</pre>
}}</pre>
===显示内容===
===显示内容===
{{gallery|caption=标题|width=300px|height=200px|perrow=2
{{gallery|caption=标题|width=200px|height=200px|perrow=2
|file:Main MPI3508.jpg|文字描述
|file:Main MPI3508.jpg|文字描述
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|
|file:4.0-HDMI-004.jpg|
}}
}}
</noinclude>
</noinclude>

Latest revision as of 20:34, 1 August 2024


标签 <gallery> 的替代品,支持gif动图

使用方法

调用参数

{{gallery|caption=<caption>|width=<width>|height=<height>|perrow=<perrow>
|file1|title1
|file2|title2
…
|fileN|titleN
}}

必填

  • file:图片名

选填

  • caption:gallery的标题
  • width:宽(单位:px)设置宽高时建议按照图片尺寸比例设置
  • height:高(单位:px)设置宽高时建议按照图片尺寸比例设置
  • perrow:每行显示数量
  • title:图片提示文字

示例1

你所写的

{{gallery
|file:Main MPI3508.jpg|文字描述
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|
}}

显示内容


示例2

你所写的

{{gallery|caption=标题|width=200px|height=200px|perrow=2
|file:Main MPI3508.jpg|文字描述
|file:4.0-HDMI-004.jpg|可以指向[[首页]]
|file:4.0-HDMI-004.jpg|
}}

显示内容