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)的更多相关文章

  1. sencha touch 在新版谷歌浏览器中painted事件无法触发解决方案以及carousel 控件、togglefield控件、滚动条失效

    在2.3/2.4版本中,新版谷歌浏览器(43.44版本)里面painted事件是不会触发的,以及carousel 控件.togglefield控件.滚动条失效,官方的解决方案如下,测试可用 会出现这个 ...

  2. sencha touch tabsidebar 源码扩展

    先上图看效果 没错,这是一个sencha touch 项目,而这里的右边推出效果(下文叫做tabsiderbar),使用插件tabsiderbar来扩展的. 插件js下载地址:http://www.m ...

  3. sencha touch 模仿tabpanel导航栏TabBar(2013-11-7)

    基于sencha touch 2.2所写 代码: /* *模仿tabpanel导航栏 */ Ext.define('ux.TabBar', { alternateClassName: 'tabBar' ...

  4. sencha touch 模仿tabpanel导航栏TabBar的实现代码

    这篇文章介绍了sencha touch 模仿tabpanel导航栏TabBar的实例代码,有需要的朋友可以参考一下 基于sencha touch 2.2所写 效果图: 代码: /* *模仿tabpan ...

  5. sencha touch 自定义cardpanel控件 模仿改进NavigationView 灵活添加按钮组,导航栏,自由隐藏返回按钮(废弃 仅参考)

    最新版本我将会放在:http://www.cnblogs.com/mlzs/p/3382229.html这里的示例里面,这里不会再做更新 代码: /* *模仿且改进NavigationView *返回 ...

  6. Sencha touch Panel之间的跳转(如不使用TabPanel或者Carousel控件而产生跳转的动画效果)

    常规的Sencha touch 应用都是"header content footer"结构,这样的结构无疑将使用TabPanel来实现,而且TabPanel肯定是card布局,这样 ...

  7. sencha touch 2 tabpanel中List的不显示问题,解决方案

    笔者在做sencha项目的时候碰到一个需求,就是"好友列表"中分为"未确认好友"和"已确认好友",两个都是一个list,自然想到的就是使用t ...

  8. sencha touch 2.2.1 自定义彩色图标按钮(button+ico)

    sencha touch 2.2.1 这个版本使用了新的按钮模式,不过他只提供了少部分的按钮样式.我们可以加一些自定义的ico样式 新加ico样式lower .x-button .x-button-i ...

  9. 关于用phonegap 3.0+ 打包后sencha touch按钮点击切换动画延迟接近一秒的以及界面闪烁的解决方案

    android的webview对硬件加速的支持貌似很不理想,在开启硬件加速的情况下,css3这些需要调用硬件加速的样式会大幅拖慢html5的webapp,在htc的部分手机上还会因开启硬件加速而导致闪 ...

随机推荐

  1. 错误 未能找到类型或命名空间名称"xxxxxx"的真正原因

    今天又被这问题撞上了,结果神奇般的解决了 谷歌了很久都没有找到真正有用的解决方案,所以在这儿写下,让更多的人看到 最根本的原因其实就是引用的问题,引用错了,然后VS在这上面提示又不够智能,所以大家被坑 ...

  2. 【WP8】富文本功能实现

    2014年8月1日更新:修复如果有多个相同链接解析失败的Bug,谢谢 @Walsh 提供的问题 富文本在移动APP上应用的最多的就是表情了,类似微博,QQ,微信都有对提供对表情和链接的支持,富文本一般 ...

  3. .NET 获取Get方式URL中的参数键值

    在Web开发中,我们常常会涉及到需要获取Get方式URL中的参数键值的情况,这里简单介绍三种方法: 第一种:常用的做法有使用JavaScript获取location.href后用正则表达式匹配获取此U ...

  4. Android学习笔记——log无法输出的解决方法和命令行查看log日志

    本人邮箱:JohnTsai.Work@gmail.com,欢迎交流讨论. 欢迎转载,转载请注明网址:http://www.cnblogs.com/JohnTsai/p/3983936.html. 知识 ...

  5. vue用阿里云oss上传图片使用分片上传只能上传100kb以内的解决办法

    首先,vue和阿里云oss上传图片结合参考了 这位朋友的 https://www.jianshu.com/p/645f63745abd 文章,成功的解决了我用阿里云oss上传图片前的一头雾水. 该大神 ...

  6. Windows 2008驱动安装失败的原因及解决方法

    希望这些内容能够帮助各位朋友顺利地在Windows Server 2008系统环境下安装使用好各种设备的驱动程序! 寻找安装失败原因 一般来说,当我们将目标设备的驱动安装光盘正确放置到Windows ...

  7. Lua中用Split函数分割字符串

    function Split(szFullString, szSeparator) local nFindStartIndex = local nSplitIndex = local nSplitAr ...

  8. DNS服务器介绍及设置

    DNS服务器是指“域名解析服务器”,而域名就是我们通常所说的“网址”.在互联网中识别和寻找不同的计算机,实际上是需要知道该计算机的IP地址才能进行访问.比如220.181.38.4,这个IP就是百度的 ...

  9. mysql 两台主主复制配置

    A.服务器 [mysqld] # The TCP/IP Port the MySQL Server will listen on port= server-id= #master-host=10.1. ...

  10. Linux静态库生成

    Linux上的静态库,其实是目标文件的归档文件. 在Linux上创建静态库的步骤如下: 写源文件,通过 gcc -c xxx.c 生成目标文件. 用 ar 归档目标文件,生成静态库. 配合静态库,写一 ...