Hybrid View
-
20 Dec 2011 3:33 AM #1
How to get correct active item as part of activeitemchage on carousel
How to get correct active item as part of activeitemchage on carousel
I have carousel with 5 items. I have added following code
Following is what gets displayed on consoleCode:Ext.ComponentMgr.get("Carousel").on("activeitemchange", function(me, value, oldValue, index) { console.log(this.getActiveIndex()); });
-1 when carousel is loaded (with 5 items)
0 when swiped to second item (left to right swipe)
1 when swiped to third item
2 when swiped to fourth item
3 when swiped back to third item (right to left swipe)
2 when swiped back to second item
1 when swiped back to 3rd item
2 when swiped back to 4th item
so the getActiveItem is not show correct value. "activeitemchange" event gets triggered after item has been switched and hence thought getActiveItem will give correct value
What am I doing wrong. I need the current Index of the item that is being changed to.
-
20 Dec 2011 4:08 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
Looks like the activeIndex is being set after the activeitemchange is happening as getActiveIndex() should return the proper index when the activeitemchange happens. The above code will get the proper index.Code:Ext.create('Ext.carousel.Carousel', { fullscreen : true, items : [ { html : 'one' }, { html : 'two' }, { html : 'three' }, { html : 'four' } ], listeners : { activeitemchange: function(carousel, newCard) { console.log(carousel.getInnerItems().indexOf(newCard)); } } });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
20 Dec 2011 9:59 PM #3


Reply With Quote