i implement this class and improve
ItemCarousel.js
Code:
Ext.define('App.ext.carousel.ItemCarousel', {
extend: 'Ext.Container',
xtype: 'itemcarousel',
config: {
src: null,
id: null,
initWidth: null,
initHeight: null,
layout: 'vbox',
scrollable: {
direction: 'both',
directionLock: false,
indicators: false,
momentumEasing: {
momentum: {
acceleration: 60,
friction: 0.3
},
bounce: {
acceleration: 30,
springTension: 0.3
}
}
},
listeners: {
painted: function () {
this.load();
},
resize:function(){
console.log(arguments,'resize')
}
}
},
load: function () {
this.removeAll();
this.add({
xtype: 'image',
cls: 'carousel-item-img',
width: this.getInitWidth(),
height: this.getInitHeight(),
style: {
'-webkit-background-size': 'contain',
'-webkit-backface-visibility': 'hidden',
'-webkit-perspective': '1000',
'-webkit-transform': 'translate3d(0, 0, 0)'
},
src: this.getSrc(),
listeners: {
load: function (img, e, eOpts) {
img.setWidth(img.imageObject.naturalWidth);
img.setHeight(img.imageObject.naturalHeight);
}
}
});
},
});
PinchCarousel
Code:
Ext.define('App.ext.carousel.PinchCarousel', {
extend: 'Ext.Carousel',
xtype: 'slideshow',
onItemAdd: function (item, index) {
var scale, perc, size,
el = item.element;
el.on({
doubletap: function (e, node, options, eOpts) {
size = el.down('.carousel-item-img').getSize();
newScale = item.parent.itemLength / size.width
width = size.width * newScale,
height = Math.round(size.height * newScale),
console.log(width, height, newScale)
el.down('.carousel-item-img').setSize(width, height);
},
pinchstart: function (e, node, options, eOpts) {
size = el.down('.carousel-item-img').getSize();
},
pinch: function (e, node, options, eOpts) {
var newScale = e.scale,
scroller = item.getScrollable().getScroller(),
width = size.width * newScale,
height = size.height * newScale,
pos = scroller.getMaxPosition();
if (height > 1920 || width > 1200 || height < 350 || width < 350) return;
el.down('.carousel-item-img').setSize(width, height);
//keeps it centered but jumpy
scroller.scrollTo(pos.x / 2, pos.y / 2);
},
pinchend: function () {
//item.getScrollable().getScroller().refresh();
},
});
this.callParent(arguments);
},
onDragStart: function (e) {
var scroller = this.getActiveItem().getScrollable().getScroller();
//ensure the image component is scrolled all the way to the edge of its scrollable container
if (e.targetTouches.length == 1 && (e.deltaX < 0 && scroller.getMaxPosition().x === scroller.position.x) || (e.deltaX > 0 && scroller.position.x == 0)) {
this.callParent(arguments);
}
},
onDrag: function (e) {
//console.log(this.getActiveItem().getScrollable().getScroller().position.x);
if (e.targetTouches.length == 1)
this.callParent(arguments);
},
onDragEnd: function (e) {
if (e.targetTouches.length < 2)
this.callParent(arguments);
}
});
how to use
Code:
var img = Ext.create('App.ext.carousel.ItemCarousel', {
src:result.Result[i].uri,
id:'image'+i,
});
mySlideShow.add(img);
i need now centralize the image.. any suggestions?