操作表是一个上滑面板,用来向用户展示进行一个任务所需的选项。
你也可以使用它来提示用户,确认潜在的危险操作。
操作表包含一个可选的标题和至少一个按钮,每个按钮都对应一个操作。
注意,不建议在大屏幕(iPad)上使用操作表。在大屏幕上,你应该使用弹出框。
创建并弹出操作表
操作表是动态元素,只能使用Javascript来创建并弹出它。让我们看一下创建操作表相关的App方法:
myApp.actions(groups) - 创建并弹出操作表,其包含指定数量群组的按钮
或者
myApp.actions(buttons) - 创建并弹出操作表,其包含一个群组,群组包含指定数量的按钮
- groups - array. 一组群组,每个群组包含若干按钮
- buttons - array. 一组按钮,这种情况下,只有一个群组
- 这个方法返回动态创建的操作表HTML元素
每个在buttons中的按钮应该作为一个对象,其包含如下参数:
参数
类型
默认值
描述
text |
字符串 |
? |
按钮上的文本(可以是HTML字符串) |
bold |
布尔值 |
false |
可选,若为真,则按钮上文本加粗 |
color |
字符串 |
? |
可选,按钮颜色,待选颜色有10种 |
bg |
string |
? |
Optional. Button background color, one of 10 default colors |
label |
布尔值 |
true |
可选,若为真,它会成为标题,而不是按钮 |
disabled |
boolean |
false |
Optional. Set to "true" if you want to make button disabled |
onClick |
函数 |
? |
可选,当用户点击该按钮时,会调用这个函数 |
让我们来看一下例子
- <body>
- ??...
-
??<div?class="page-content">
-
????<div?class="content-block">
-
??????<p><a?href="#"?class="ac-1">One?group,?three?buttons</a></p>
-
??????<p><a?href="#"?class="ac-2">One?group,?title,?three?buttons</a></p>
-
??????<p><a?href="#"?class="ac-3">Two?groups</a></p>
-
??????<p><a?href="#"?class="ac-4">Three?groups</a></p>
-
??????<p><a?href="#"?class="ac-5">With?callbacks?on?click</a></p>
-
????</div>
-
??</div>
- ??...
- </body>
复制
-
var?myApp?=?new?Framework7();
- ?
-
var?$$?=?Dom7;
- ?
- //-?One?group,?three?buttons
-
$$(‘.ac-1‘).on(‘click‘,?function?()?{
-
????var?buttons?=?[
-
????????{
-
????????????text:?‘Button1‘,
-
????????????bold:?true
-
????????},
-
????????{
-
????????????text:?‘Button2‘
-
????????},
-
????????{
-
????????????text:?‘Cancel‘,
-
????????????color:?‘red‘
-
????????},
-
????];
-
????myApp.actions(buttons);
- });
- ?
- //-?One?group,?title,?three?buttons
-
$$(‘.ac-2‘).on(‘click‘,?function?()?{
-
????var?buttons?=?[
-
????????{
-
????????????text:?‘Do?something‘,
-
????????????label:?true
-
????????},
-
????????{
-
????????????text:?‘Button1‘,
-
????????????bold:?true
-
????????},
-
????????{
-
????????????text:?‘Button2‘,
-
????????},
-
????????{
-
????????????text:?‘Cancel‘,
-
????????????color:?‘red‘
-
????????},
-
????];
-
????myApp.actions(buttons);
- });
- ?
- //-?Two?groups
-
$$(‘.ac-3‘).on(‘click‘,?function?()?{
-
????var?buttons1?=?[
-
????????{
-
????????????text:?‘Do?something‘,
-
????????????label:?true
-
????????},
-
????????{
-
????????????text:?‘Button1‘,
-
????????????bold:?true
-
????????},
-
????????{
-
????????????text:?‘Button2‘,
-
????????}
-
????];
-
????var?buttons2?=?[
-
????????{
-
????????????text:?‘Cancel‘,
-
????????????color:?‘red‘
-
????????}
-
????];
-
????var?groups?=?[buttons1,?buttons2];
-
????myApp.actions(groups);
- });
- ?
- //-?Three?groups
-
$$(‘.ac-4‘).on(‘click‘,?function?()?{
-
????var?buttons1?=?[
-
????????{
-
????????????text:?‘Share‘,
-
????????????label:?true
-
????????},
-
????????{
-
????????????text:?‘Mail‘,
-
????????},
-
????????{
-
????????????text:?‘Messages‘,
-
????????}
-
????];
-
????var?buttons2?=?[
-
????????{
-
????????????text:?‘Social?share‘,
-
????????????label:?true
-
????????},
-
????????{
-
????????????text:?‘Facebook‘,
-
????????},
-
????????{
-
????????????text:?‘Twitter‘,
-
????????}
-
????];
-
????var?buttons3?=?[
-
????????{
-
????????????text:?‘Cancel‘,
-
????????????color:?‘red‘
-
????????}
-
????];
-
????var?groups?=?[buttons1,?buttons2,?buttons3];
-
????myApp.actions(groups);
- });
- ?
- //-?With?callbacks?on?click
-
$$(‘.ac-5‘).on(‘click‘,?function?()?{
-
????var?buttons?=?[
-
????????{
-
????????????text:?‘Button1‘,
-
????????????onClick:?function?()?{
-
????????????????myApp.alert(‘Button1?clicked‘);
-
????????????}
-
????????},
-
????????{
-
????????????text:?‘Button2‘,
-
????????????onClick:?function?()?{
-
????????????????myApp.alert(‘Button2?clicked‘);
-
????????????}
-
????????},
-
????????{
-
????????????text:?‘Cancel‘,
-
????????????color:?‘red‘,
-
????????????onClick:?function?()?{
-
????????????????myApp.alert(‘Cancel?clicked‘);
-
????????????}
-
????????},
-
????];
-
????myApp.actions(buttons);
- });
复制
实例预览
移动端安卓和IOS开发框架Framework7教程-Popover 布局
原文:http://zaixianshouce.iteye.com/blog/2303023