sencha touch 模仿tabpanel导航栏TabBar的实现代码
来源:互联网 发布:北京摩比数据 编辑:程序博客网 时间:2024/05/14 12:18
这篇文章介绍了sencha touch 模仿tabpanel导航栏TabBar的实例代码,有需要的朋友可以参考一下
/*
*模仿tabpanel导航栏
*/
Ext.define('ux.TabBar', {
alternateClassName: 'tabBar',
extend: 'Ext.Toolbar',
xtype: 'tabBar',
config: {
docked: 'bottom',
cls: 'navToolbar',
layout: {
align: 'stretch'
},
defaults: {
flex: 1
},
//被选中的按钮
selectButton: null
},
initialize: function () {
var me = this;
me.callParent();
//监听按钮点击事件
me.on({
delegate: '> button',
scope: me,
tap: 'onButtonTap'
});
},
//更新被选中按钮
updateSelectButton: function (newItem, oldItem) {
console.log(oldItem);
if (oldItem) {
oldItem.removeCls('x-tabBar-pressing');
}
if (newItem) {
newItem.addCls('x-tabBar-pressing');
}
},
//当按钮被点击时
onButtonTap: function (button) {
this.setSelectButton(button);
},
/**
* @private
*执行添加项,调用add方法后自动执行
*/
onItemAdd: function (item, index) {
if (!this.getSelectButton() && item.getInitialConfig('selected')) {
this.setSelectButton(item);
}
this.callParent(arguments);
}
});
需要的css:
复制代码 代码如下:
.navToolbar {
padding:0;
}
.navToolbar .x-button {
border:0;
margin:0;
border-right:1px solid #585B5B;
border-radius:0;
padding:0;
}
.navToolbar .x-button .x-button-label {
font-weight:normal;
color:White;
font-size:0.6em;
}
.navToolbar .x-tabBar-pressing {
background-image:none;
background-color:#0f517e;
background-image:-webkit-gradient(linear,50% 0%,50% 100%,color-stop(0%,#0a3351),color-stop(10%,#0c4267),color-stop(65%,#0f517e),color-stop(100%,#0f5280));
background-image:-webkit-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-moz-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-o-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
}
使用:
复制代码 代码如下:
Ext.define('app.view.MyBar', {
alternateClassName: 'myBar',
extend: 'ux.TabBar',
xtype: 'myBar',
config: {
items: [
{
xtype: 'button',
text: '问卷调查',
//只有第一个设置的属性有效
selected: true
},
{
xtype: 'button',
text: '我的积分'
},
{
xtype: 'button',
text: '开奖大厅'
},
{
xtype: 'button',
text: '幸运号码'
},
{
xtype: 'button',
text: '更多'
}]
}
});
基于sencha touch 2.2所写
效果图:
/*
*模仿tabpanel导航栏
*/
Ext.define('ux.TabBar', {
alternateClassName: 'tabBar',
extend: 'Ext.Toolbar',
xtype: 'tabBar',
config: {
docked: 'bottom',
cls: 'navToolbar',
layout: {
align: 'stretch'
},
defaults: {
flex: 1
},
//被选中的按钮
selectButton: null
},
initialize: function () {
var me = this;
me.callParent();
//监听按钮点击事件
me.on({
delegate: '> button',
scope: me,
tap: 'onButtonTap'
});
},
//更新被选中按钮
updateSelectButton: function (newItem, oldItem) {
console.log(oldItem);
if (oldItem) {
oldItem.removeCls('x-tabBar-pressing');
}
if (newItem) {
newItem.addCls('x-tabBar-pressing');
}
},
//当按钮被点击时
onButtonTap: function (button) {
this.setSelectButton(button);
},
/**
* @private
*执行添加项,调用add方法后自动执行
*/
onItemAdd: function (item, index) {
if (!this.getSelectButton() && item.getInitialConfig('selected')) {
this.setSelectButton(item);
}
this.callParent(arguments);
}
});
需要的css:
复制代码 代码如下:
.navToolbar {
padding:0;
}
.navToolbar .x-button {
border:0;
margin:0;
border-right:1px solid #585B5B;
border-radius:0;
padding:0;
}
.navToolbar .x-button .x-button-label {
font-weight:normal;
color:White;
font-size:0.6em;
}
.navToolbar .x-tabBar-pressing {
background-image:none;
background-color:#0f517e;
background-image:-webkit-gradient(linear,50% 0%,50% 100%,color-stop(0%,#0a3351),color-stop(10%,#0c4267),color-stop(65%,#0f517e),color-stop(100%,#0f5280));
background-image:-webkit-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-moz-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:-o-linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
background-image:linear-gradient(top,#0a3351,#0c4267 10%,#0f517e 65%,#0f5280);
}
使用:
复制代码 代码如下:
Ext.define('app.view.MyBar', {
alternateClassName: 'myBar',
extend: 'ux.TabBar',
xtype: 'myBar',
config: {
items: [
{
xtype: 'button',
text: '问卷调查',
//只有第一个设置的属性有效
selected: true
},
{
xtype: 'button',
text: '我的积分'
},
{
xtype: 'button',
text: '开奖大厅'
},
{
xtype: 'button',
text: '幸运号码'
},
{
xtype: 'button',
text: '更多'
}]
}
});
0 0
- sencha touch 模仿tabpanel导航栏TabBar的实现代码
- 【sencha-touch】TabPanel的使用
- sencha touch NavigationView 嵌套 TabPanel 的问题
- Sencha Touch中TabPanel组件的使用
- sencha touch之让tabPanel的tab居中
- 关于Sencha Touch tabpanel的items置顶居中显示
- Sencha Touch中TabPanel组件的使用(转)
- sencha touch 中navigationview嵌套tabpanel出现的问题
- sencha touch 自定义cardpanel控件 模仿改进NavigationView 灵活添加按钮组,导航栏,自由隐藏返回按钮
- sencha touch之panel和tabpanel
- 解决Sencha Touch tabpanel滚动条问题
- [Sencha ExtJS & Touch] VS Code 的 Sencha 扩展(智能提示,代码导航和集成Build操作等)
- Sencha-touch之TabPanel的Tab在点击时实施事件
- sencha-touch开发的一些tips(tabPanel,提示框,store数据修改)
- sencha touch 2 tabpanel中List的不显示问题,解决方案
- sencha touch的tabpanel里tab比较多时,使tab子标签滚动
- sencha touch 搜索功能search的实现
- Sencha Touch 2 toolbar 按钮模仿开始菜单
- 如何安装体验 Ubuntu on Windows
- 斐波纳契数列
- 模板设计模式_组合&继承实现
- 【BZOJ1664】[Usaco2006 Open]County Fair Events 参加节日庆祝【线段覆盖】【贪心】
- android launchMode加载模式和intent flag
- sencha touch 模仿tabpanel导航栏TabBar的实现代码
- android程序启动画面之Splash总结
- 为雇员增加工资,从工资低的雇员开始,为每个人增加原工资的 10%,限定所增加的工资总额为 800 元,显示增加工资的人数和余额。
- 卖票小系统(关于线程同步的问题)
- JAVA文件中获取路径及WEB应用程序获取路径方法
- hdu_5705_Clock("巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场)
- POJ 2440 DNA(递推)
- 让你的APP支持不同的设备
- springMVC-@RequestMapping注解