This widget help building a beautiful accordion panel.
<section data-am-widget="accordion" class="am-accordion am-accordion-default" data-am-accordion='{ "multiple": true }'>
<dl class="am-accordion-item am-active am-disabled">
<dt class="am-accordion-title">
就这样恣意的活着
</dt>
<dd class="am-accordion-bd am-collapse am-in">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
置身人群中 <br/> 你只需要被淹没 享受 沉默 <br/> 退到人群后 <br/> 你只需给予双手 微笑 等候
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
让生命去等候,去等候,去等候,去等候
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
走在忠孝东路 <br/> 徘徊在茫然中 <br/> 在我的人生旅途 <br/> 选择了多少错误 <br/> 我在睡梦中惊醒 <br/> 感叹悔言无尽 <br/> 恨我不能说服自己 <br/> 接受一切教训 <br/> 让生命去等候 <br/> 等候下一个漂流 <br/> 让生命去等候 <br/>等候下一个伤口
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
我就这样告别山下的家
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
我就这样告别山下的家,我实在不愿轻易让眼泪留下。我以为我并不差不会害怕,我就这样自己照顾自己长大。我不想因为现实把头低下,我以为我并不差能学会虚假。怎样才能够看穿面具里的谎话?别让我的真心散的像沙。如果有一天我变得更复杂,还能不能唱出歌声里的那幅画?
</div>
</dd>
</dl>
</section>
<section data-am-widget="accordion" class="am-accordion am-accordion-basic" data-am-accordion='{ }'>
<dl class="am-accordion-item am-active">
<dt class="am-accordion-title">
就这样恣意的活着
</dt>
<dd class="am-accordion-bd am-collapse am-in">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
置身人群中 <br/> 你只需要被淹没 享受 沉默 <br/> 退到人群后 <br/> 你只需给予双手 微笑 等候
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
让生命去等候,去等候,去等候,去等候
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
走在忠孝东路 <br/> 徘徊在茫然中 <br/> 在我的人生旅途 <br/> 选择了多少错误 <br/> 我在睡梦中惊醒 <br/> 感叹悔言无尽 <br/> 恨我不能说服自己 <br/> 接受一切教训 <br/> 让生命去等候 <br/> 等候下一个漂流 <br/> 让生命去等候 <br/>等候下一个伤口
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
我就这样告别山下的家
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
我就这样告别山下的家,我实在不愿轻易让眼泪留下。我以为我并不差不会害怕,我就这样自己照顾自己长大。我不想因为现实把头低下,我以为我并不差能学会虚假。怎样才能够看穿面具里的谎话?别让我的真心散的像沙。如果有一天我变得更复杂,还能不能唱出歌声里的那幅画?
</div>
</dd>
</dl>
</section>
<section data-am-widget="accordion" class="am-accordion am-accordion-gapped" data-am-accordion='{ }'>
<dl class="am-accordion-item am-active">
<dt class="am-accordion-title">
就这样恣意的活着
</dt>
<dd class="am-accordion-bd am-collapse am-in">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
置身人群中 <br/> 你只需要被淹没 享受 沉默 <br/> 退到人群后 <br/> 你只需给予双手 微笑 等候
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
让生命去等候,去等候,去等候,去等候
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
走在忠孝东路 <br/> 徘徊在茫然中 <br/> 在我的人生旅途 <br/> 选择了多少错误 <br/> 我在睡梦中惊醒 <br/> 感叹悔言无尽 <br/> 恨我不能说服自己 <br/> 接受一切教训 <br/> 让生命去等候 <br/> 等候下一个漂流 <br/> 让生命去等候 <br/>等候下一个伤口
</div>
</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">
我就这样告别山下的家
</dt>
<dd class="am-accordion-bd am-collapse ">
<!-- 规避 Collapase 处理有 padding 的折叠内容计算计算有误问题, 加一个容器 -->
<div class="am-accordion-content">
我就这样告别山下的家,我实在不愿轻易让眼泪留下。我以为我并不差不会害怕,我就这样自己照顾自己长大。我不想因为现实把头低下,我以为我并不差能学会虚假。怎样才能够看穿面具里的谎话?别让我的真心散的像沙。如果有一天我变得更复杂,还能不能唱出歌声里的那幅画?
</div>
</dd>
</dl>
</section>
<body>
of the Amaze UI HTML template(Download);First, import Handlebars library and amui.widget.helper.js
(See widget.html
file in Amaze UI HTML Template).
Then use either following ways to bind data.
1. Insert the script of widget into the template:
<script type="text/x-handlebars-template" id="my-tpl"></script>
Then query the template and pass the data to it.
$(function() {
var $tpl = $('#my-tpl'),
tpl = $tpl.text(),
template = Handlebars.compile(tpl),
data = {
accordionData: {
"theme": "basic",
"content": [
{
"title": "Title 1",
"content": "Content 1",
"active": true
},
{
"title": "Title 2",
"content": "Content 2"
},
{
"title": "Title 3",
"content": "Content 3"
}
]
}
},
html = template(data);
$tpl.before(html);
});
The rendered HTML looks like this:
<section data-am-widget="accordion" class="am-accordion am-accordion-basic doc-accordion-class"
id="doc-accordion-example" data-accordion-settings="{ }">
<dl class="am-accordion-item am-active">
<dt class="am-accordion-title">Title 1</dt>
<dd class="am-accordion-content">Content 1</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">Title 2</dt>
<dd class="am-accordion-content">Content 2</dd>
</dl>
<dl class="am-accordion-item">
<dt class="am-accordion-title">Title 3</dt>
<dd class="am-accordion-content">Content 3</dd>
</dl>
</section>
If there are other widget or templates in the same page, we recommend using this way. Maintenance will be easier in this way.
Second, Directly render the widget with Handlebars:
var template = Handlebars.compile('{{>accordion}}'),
data = {
accordionData: {
"id": "doc-accordion-example",
"className": "doc-accordion-class",
"theme": "basic",
"content": [
{
"title": "Title 1",
"content": "Content 1",
"active": true
},
{
"title": "Title 2",
"content": "Content 2"
},
{
"title": "Title 3",
"content": "Content 3"
}
]
}
},
html = template(data.accordionData);
$('body').append(html);
Data binding
button on the right panel, and bind data using following format.var data = [
{
"title": "", // Title. Support using html
"content": "" // Content. Support using html
}
];
return data;
{
// ID
"id": "",
// Customized class
"className": "",
// Theme
"theme": "",
"options": {
"multiple": false // Allow opening multiple panel at the same time. Default value is FALSE.
},
// Content(* means required)
"content": [
{
"title": "", // Title. Support using html
"content": "", // Content. Support using html
"active": false // Whether activate current panel.
// New in Amaze UI 2.3
"disabled": null // Whether diable current panel.
}
]
}
padding
/margin
/border
for .am-accordion-bd
.