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. 各大引擎矩阵的矩阵存储方式 ----行矩阵 or 列矩阵

    OpenGL  里面的矩阵 float  m[16]; OpenGL中的矩阵是这样的 m[0] m[4] m[8] m[12] m[1] m[5] m[9] m[13] m[2] m[6] m[10] ...

  2. 通过NAT转发实现私网对外发布信息

    我们可以在防火墙的外部网卡上绑定多个合法IP地址,然后通过ip映射使发给其中某一个IP地址的包转发至内部某一用户的WWW服务器上,然后再将该内部WWW服务器响应包伪装成该合法IP发出的包. 具体的IP ...

  3. TXT文件用法大全【荐】--------按键精灵

    来源:全文链接 (3)读取TXT文件指定某一行的第?到第?个字 UserVar t=2 "读出txt第几行文本" UserVar i=5 "从第几个字开始读取" ...

  4. 184使用 Core Image 框架处理照片

    实现图片的老旧.色彩.旋转效果 (1)使用 StoryBoard 故事版布局界面: (2)使用 Core Image 框架的 CIFilter 过滤器:分别对应的过滤器名称是:CISepiaTone( ...

  5. js粘贴事件paste简单解析及遇到的坑

    在用户执行粘贴操作的时候,js能够获得剪切板的内容,本文讨论一下这个问题. 目前只有Chrome支持获取剪切板中的图片数据.还好需要这个功能的产品目前只支持Chrome和Safari,一些Chrome ...

  6. 如何构建高性能MySQL索引

    本文的重点在于如何构建一个高性能的MySQL索引,从中你可以学到如何分析一个索引是不是好索引,以及如何构建一个好的索引. 索引误区 多列索引 一个索引的常见误区是为每一列创建一个索引,如下面创建的索引 ...

  7. php下webservice使用总结

    基于thinkphp3.2的 1.修改php配置 php.ini extension=php_soap.dll soap.wsdl_cache_enabled=0 2.soap有两种模式 wsdl和 ...

  8. ios Develop mark

    App Distribution Guidehttps://developer.apple.com/library/ios/documaentation/IDEs/Conceptual/AppDist ...

  9. MyBatis 与 Spring 是如何结合在一起工作的——mybatis-spring(version:1.2.2)

    在MyBatis-Spring的项目中,我们一般会为MyBatis配置两个配置文件 beans-mybatis.xml 和 mybatis-config.xml.其中 beans-mybatis.xm ...

  10. Linux下tomcat无法启动

    场景:干净的tomcat,刚解压 1 通过./startup.sh,提示启动成功,但查看没有日志 2 通过netstat -tln查看端口,发现找不到8080 3 通过./catalina.sh ru ...