sencha touch TabPanel 加入导航按钮(向左向右按钮) 以及Carousel插件(2014-11-7)
Carousel插件代码:
/*
* TabPanel的Carousel功能插件
* 取至
* https://github.com/VinylFox/Ext.ux.touch.SwipeTabs
*/
Ext.define('ux.plugin.SwipeTabs', {
alias: 'plugin.swipetabs',
xtype: 'swipetabs',
config: {
cmp: null,
//是否循环滚动
allowOverflow: false,
animation: {
duration: 300,
easing: 'ease-out',
type: 'slide'
},
/**
* @cfg {Object} [allowDirections=['left', 'right', 'up', 'down',]] 只有指定方向可以切换.
* @private
* @accessor
*/
allowDirections: ['left', 'right']
},
constructor: function (config) {
this.initConfig(config);
this.callParent([config]);
},
init: function (cmp) {
this.setCmp(cmp);
},
updateCmp: function (newCmp, oldCmp) {
if (oldCmp) {
oldCmp.element.un('swipe', this.onSwipe);
}
if (newCmp) {
newCmp.element.on('swipe', this.onSwipe, this);
}
},
onSwipe: function (e) {
if (this.getAllowDirections().indexOf(e.direction) < 0) {
return;
}
var cmp = this.getCmp(),
allowOverflow = this.getAllowOverflow(),
animation = this.getAnimation(),
//获取切换动画效果
direction = e.direction,
//滑动方向
activeItem = cmp.getActiveItem(),
//当前选中项
innerItems = cmp.getInnerItems(),
//所有项
numIdx = innerItems.length - 1,
//最大索引
idx = Ext.Array.indexOf(innerItems, activeItem),
//当前选中项索引
newIdx = idx + (direction === 'left' ? 1 : -1),
//目标索引
newItem;
//处理目标索引,避免出错
if (newIdx < 0) {
if (allowOverflow) {
newItem = innerItems[numIdx];
}
} else if (newIdx > numIdx) {
if (allowOverflow) {
newItem = innerItems[0];
}
} else {
newItem = innerItems[newIdx]
}
if (newItem) {
animation = Ext.apply({},
{
direction: direction
},
animation);
//切换
cmp.animateActiveItem(newItem, animation);
//设置导航滚动
var mun = cmp.getInitialConfig('moveNum'),
scrollable;
if (mun && mun > 0) {
scrollable = cmp.getTabBar().getScrollable();
if (scrollable) {
scrollable.getScroller().scrollTo(newIdx * mun, 0);
}
}
}
}
});
加入左右导航按钮代码:
/*
*为TabPanel加上向左向右按钮
*选项较多时可以滚动
*/
Ext.define('ux.PageTab', {
extend: 'Ext.TabPanel',
xtype: 'pageTab',
config: {
//每次移动的距离
moveNum: 41,
//是否循环滚动
allowOverflow: false,
//向右翻页按钮
rightBtn: {
iconMask: true,
iconCls: 'maskIco arrow_right',
name: 'move',
action: 1,
docked: 'right'
},
//向左翻页按钮
leftBtn: {
iconCls: 'maskIco arrow_left',
iconMask: true,
action: -1,
name: 'move',
docked: 'left'
},
//设置横向滚动条
tabBar: {
cls: 'pageTab',
scrollable: {
direction: 'horizontal',
//隐藏滚动条样式
indicators: false
}
}
},
//创建右翻页按钮
applyRightBtn: function (config) {
return Ext.factory(config, Ext.Button, this.getRightBtn());
},
//更新右翻页按钮
updateRightBtn: function (newRightBtn, oldRightBtn) {
this.updateMoveBtn(newRightBtn, oldRightBtn);
},
//创建左翻页按钮
applyLeftBtn: function (config) {
return Ext.factory(config, Ext.Button, this.getLeftBtn());
},
//更新左翻页按钮
updateLeftBtn: function (newLeftBtn, oldLeftBtn) {
this.updateMoveBtn(newLeftBtn, oldLeftBtn);
},
//更新翻页按钮
updateMoveBtn: function (newMoveBtn, oldMoveBtn) {
if (oldMoveBtn) {
this.getTabBar().remove(oldMoveBtn);
}
if (newMoveBtn) {
this.getTabBar().add(newMoveBtn);
newMoveBtn.on({
scope: this,
tap: this.onTabMove
});
}
},
//点击翻页按钮执行
onTabMove: function (btn) {
//获取当前项
var activeItem = this.getActiveItem(),
//是否循环滚动
allowOverflow = this.getAllowOverflow(),
//获取所有项
innerItems = this.getInnerItems(),
//获取最大索引
numIdx = innerItems.length - 1,
//获取当前选中项索引
idx = Ext.Array.indexOf(innerItems, activeItem),
//获取点击按钮后索引
newIdx = idx + btn.config.action;
if (newIdx < 0) {
if (!allowOverflow) return;
newIdx = numIdx;
} else if (newIdx > numIdx) {
if (!allowOverflow) return;
newIdx = 0;
}
//选中新项
this.setActiveItem(newIdx);
this.setScroll(newIdx);
},
//选择项
selectView: function (itemId) {
//获取所有项
var me = this, innerItems = me.getInnerItems(), i, ln, item;
for (i = 0, ln = innerItems.length; i < ln; i++) {
item = innerItems[i];
if (item.getItemId() == itemId) {
me.setActiveItem(item);
me.setScroll(i);
break;
}
}
},
//设置滚动条
setScroll: function (newIdx) {
//设置新的滚动位置
var mun = this.getMoveNum();
if (mun && mun > 0) {
var scr = this.getTabBar().getScrollable().getScroller();
scr.scrollTo(newIdx * mun, 0);
}
}
});
所需css:
.x-tabpanel .pageTab {
padding:;
}
.pageTab .x-button {
border:;
padding:;
background-color:transparent;
background-image:none;
}
.pageTab .x-button .x-button-icon {
width: 1.5em;
margin:0.5em 0;
-webkit-mask-size:auto 100%;
background-color:#EEEFEF;
background-image:none;
}
.pageTab .x-button.x-button-pressing .x-button-icon {
background-color:#2A8BBE;
}
使用示例:
Ext.define('app.view.action.List', {
alternateClassName: 'actionList',
extend: 'ux.PageTab',
xtype: 'actionList',
requires: ['ux.plugin.SwipeTabs', 'app.view.action.TabList'],
config: {
cls: 'tab',
plugins: 'swipetabs',
items: [{
title: '校园活动',
xtype: 'actionTabList',
store: 'actionCampusList'
},
{
title: '其它活动',
xtype: 'actionTabList',
store: 'actionCampusList'
},
{
title: '讲座报告',
xtype: 'actionTabList',
store: 'actionCampusList'
},
{
title: '公益活动',
xtype: 'actionTabList',
store: 'actionCampusList'
},
{
title: '比赛活动',
xtype: 'actionTabList',
store: 'actionCampusList'
},
{
title: '招聘实习',
xtype: 'actionTabList',
store: 'actionCampusList'
}, {
title: '社团活动',
xtype: 'actionTabList',
store: 'actionCampusList'
}]
}
});
示例部分css:
.tab {
height:100%;
}
.tab .x-tabbar-dark {
background-image:none;
background-color:#D3DCE3;
padding:;
border:;
}
.tab .x-tabbar-dark .x-tab {
color:#677C8B;
border:;
height:100%;
border-radius:;
padding:0.8em 0.2em;
}
.tab .x-tabbar-dark .x-tab-active {
background-color:transparent;
background-image:none;
border-bottom:1px solid #00A4FF;
color:#060606;
}
效果:

2013.9.6
优化PageTab内for循环结构
2014.11.7
修复bug,适配到2.4.1版本
sencha touch TabPanel 加入导航按钮(向左向右按钮) 以及Carousel插件(2014-11-7)的更多相关文章
- sencha touch 在新版谷歌浏览器中painted事件无法触发解决方案以及carousel 控件、togglefield控件、滚动条失效
在2.3/2.4版本中,新版谷歌浏览器(43.44版本)里面painted事件是不会触发的,以及carousel 控件.togglefield控件.滚动条失效,官方的解决方案如下,测试可用 会出现这个 ...
- sencha touch tabsidebar 源码扩展
先上图看效果 没错,这是一个sencha touch 项目,而这里的右边推出效果(下文叫做tabsiderbar),使用插件tabsiderbar来扩展的. 插件js下载地址:http://www.m ...
- sencha touch 模仿tabpanel导航栏TabBar(2013-11-7)
基于sencha touch 2.2所写 代码: /* *模仿tabpanel导航栏 */ Ext.define('ux.TabBar', { alternateClassName: 'tabBar' ...
- sencha touch 模仿tabpanel导航栏TabBar的实现代码
这篇文章介绍了sencha touch 模仿tabpanel导航栏TabBar的实例代码,有需要的朋友可以参考一下 基于sencha touch 2.2所写 效果图: 代码: /* *模仿tabpan ...
- sencha touch 自定义cardpanel控件 模仿改进NavigationView 灵活添加按钮组,导航栏,自由隐藏返回按钮(废弃 仅参考)
最新版本我将会放在:http://www.cnblogs.com/mlzs/p/3382229.html这里的示例里面,这里不会再做更新 代码: /* *模仿且改进NavigationView *返回 ...
- Sencha touch Panel之间的跳转(如不使用TabPanel或者Carousel控件而产生跳转的动画效果)
常规的Sencha touch 应用都是"header content footer"结构,这样的结构无疑将使用TabPanel来实现,而且TabPanel肯定是card布局,这样 ...
- sencha touch 2 tabpanel中List的不显示问题,解决方案
笔者在做sencha项目的时候碰到一个需求,就是"好友列表"中分为"未确认好友"和"已确认好友",两个都是一个list,自然想到的就是使用t ...
- sencha touch 2.2.1 自定义彩色图标按钮(button+ico)
sencha touch 2.2.1 这个版本使用了新的按钮模式,不过他只提供了少部分的按钮样式.我们可以加一些自定义的ico样式 新加ico样式lower .x-button .x-button-i ...
- 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案
android的webview对硬件加速的支持貌似很不理想,在开启硬件加速的情况下,css3这些需要调用硬件加速的样式会大幅拖慢html5的webapp,在htc的部分手机上还会因开启硬件加速而导致闪 ...
随机推荐
- 强大!HTML5 3D美女图片旋转实现教程
又到周末,来弄点HTML5的特效玩玩,今天要折腾的是HTML5 3D图片特效,图片在垂直方向上被分割成一条条小矩形,在图片上拖动鼠标即可让每一个小矩形旋转,从而让图片形成3D立体的效果,来看看效果图: ...
- Vue文件跳转$router传参数
<button @click = "func()">跳转</button> //js <script> export default{ meth ...
- Java基础--深克隆补充
深克隆文章很多,这里推荐Java提高篇--对象克隆(复制). 以上文章条理清晰,一目了然,但最近在项目中碰到的实际问题是,所要克隆的对象是加上子类父类共计207个,无论用上述两种方式的哪一种,都要一一 ...
- Capability Model
Data Scientist, Analytics We’re looking for data scientists to work on our core and business product ...
- Lua之转义字符
print("\a"); --bell 硬件滴一声 print("a"); print("\b"); --back space ...
- 怎么用ABBYY在线浏览PDF文件
ABBYY FineReader 让您可以从在线存储服务中打开图像或 PDF 文件,并将已识别文本保存至在线存储服务中,如 Dropbox.SkyDrive 或 Google Drive 等.通过在 ...
- springMVC中如何访问WebContent中的资源文件
一.问题: 我的工程目录如下: WebContent |-css |-js |-imgs |-META-INF |-WEB-INF |-jsp |-login.jsp 如何在login.jsp中引用i ...
- Visual Code 调用Chrome 浏览HTML
Code 使用快捷键:Ctrl+Shit+B 然后再Task.json,替换以下: { "version": "0.1.0", "command&qu ...
- python获取数组中最多的元素
获取数组中数量最多的元素,也就是最频繁的那个元素,方法有很多,下面是3种最简单的: 用max函数 sample = [1,2,3,3,3,4,5,5] max(set(sample), key=sam ...
- [Model] LeNet-5 by Keras
典型的卷积神经网络. 数据的预处理 Keras傻瓜式读取数据:自动下载,自动解压,自动加载. # X_train: array([[[[ 0., 0., 0., ..., 0., 0., 0.], [ ...