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. GridView如何将分页数据全部导出为EXCEL?

    GRIDVIEW分页状态下将全部数据导出 protected void Button2_Click(object sender, EventArgs e)//按button2将gridview将数据导 ...

  2. 【Postgresql】set up

    https://www.howtoforge.com/tutorial/ubuntu-postgresql-installation/ https://linux.cn/article-6770-1. ...

  3. VCL 中的 Windows API 函数(1): AbortDoc

    AbortDoc: 该函数终止当前打印作业并删除最好一次调用 StartDoc 函数写入的所有信息. 该函数在 Printers 单元的应用:AbortDoc(Canvas.Handle);

  4. Python 中遍历序列中元素和下标

    enumerate 函数用于遍历序列中的元素以及它们的下标 for i,v in enumerate(['tic','tac','toe']): print i,v #0 tic #1 tac #2 ...

  5. Ubuntu18.10安装网易云音乐(图文并茂!)

    听音乐,怎么少得了网易云音乐,下面我们在Ubuntu18.10上来安装下: 首先进入网易云音乐的下载页:https://music.163.com/#/download,选择下载Ubuntu版本: 我 ...

  6. Yslow-23条军规

    YslowYahoo发布的一款基于FireFox的插件,主要是为了提高网页性能而设计的,下面是它提倡了23条规则,还是很不错的,分享一下: 1.减少HTTP请求次数 合并图片.CSS.JS,改进首次访 ...

  7. yum和apt-get用法及区别

    https://www.cnblogs.com/garinzhang/p/diff_between_yum_apt-get_in_linux.html

  8. HTML5标签canvas制作动画

    摘要: canvas可以绘制图像,自然而然的就可以制作动画,因为动画的每一帧都是图像.我们可以利用javascript的setInterval函数来实现动画效果. 下面是一个例子,小圆绕着红点圆心不停 ...

  9. [Bayesian] “我是bayesian我怕谁”系列 - Exact Inference

    要整理这部分内容,一开始我是拒绝的.欣赏贝叶斯的人本就不多,这部分过后恐怕就要成为“从入门到放弃”系列. 但,这部分是基础,不管是Professor Daphne Koller,还是统计学习经典,都有 ...

  10. InnoDB锁问题 & DB事务隔离级别

    <参考:http://www.cnblogs.com/jack204/archive/2012/06/09/2542940.html>InnoDB行锁实现方式InnoDB行锁是通过给索引上 ...