简体   繁体   English

Sencha Touch 2轮播指示器点击事件

[英]Sencha Touch 2 carousel indicator tap events

I have a Sencha Touch 2 carousel (see http://dev.sencha.com/deploy/touch/examples/production/carousel/index.html ). 我有一个Sencha Touch 2传送带(请参阅http://dev.sencha.com/deploy/touch/examples/production/carousel/index.html )。 I need to capture the event when the active item is first and the user tries to navigate back. 当活动项目为第一个并且用户尝试向后导航时,我需要捕获事件。 Also, when the active item is the last and the user tries to navigate forward. 同样,当活动项目是最后一个项目并且用户尝试向前导航时。

I haven't found on Sencha Touch docs anything close to my needs: http://docs.sencha.com/touch/2.2.0/#!/api/Ext.carousel.Carousel 我在Sencha Touch文档上没有找到任何满足我需求的东西: http : //docs.sencha.com/touch/2.2.0/#!/api/Ext.carousel.Carousel

Let's start from here: 让我们从这里开始:

Ext.create('Ext.Carousel', {
fullscreen: true,

defaults: {
    styleHtmlContent: true
},

items: [
    {
        html : 'Item 1',
        style: 'background-color: #5E99CC'
    },
    {
        html : 'Item 2',
        style: 'background-color: #759E60'
    },
    {
        html : 'Item 3'
    }
]});
    var activeItem = 0; // initial active carousel item
    Ext.create('Ext.Carousel', {
    fullscreen: true,
    id: 'q-car',
    defaults: {
        styleHtmlContent: true
    },
    initialize: function(){
        var caru = Ext.getCmp('q-car'),
            ind = caru.getIndicator();

        ind.onTap = function(e){
            var touch = e.touch,
                box = this.element.getPageBox(),
                centerX = box.left + (box.width / 2),
                centerY = box.top + (box.height / 2),
                direction = this.getDirection(),
                itemsCount = caru.getItems().length-2; // items length includes the indicator bar.

            if(direction === 'horizontal'){
                if(touch.pageX >= centerX){
                    if(activeItem < itemsCount){
                        this.fireEvent('next', this);
                        activeItem++                                                
                    }else{
                        console.log('end of carousel')
                    }
                }else{
                    if(activeItem > 0){
                        this.fireEvent('next', this);
                        activeItem--                                                
                    }else{
                        console.log('begin of carousel')
                    }
                }       
            }
        }
    },
    items: [
        {
            html : 'Item 1',
            style: 'background-color: #5E99CC'
        },
        {
            html : 'Item 2',
            style: 'background-color: #759E60'
        },
        {
            html : 'Item 3'
        }
    ]});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM