View Full Version : CardLayout override which fades the cards in/out
Animal
16 Sep 2008, 6:47 AM
You need to use layoutConfig: { animate: true } to make it animate.
Ext.override(Ext.layout.CardLayout, {
setActiveItem : function(item){
item = this.container.getComponent(item);
if(this.activeItem != item){
if (item.rendered && this.animate) {
Ext.Fx.syncFx();
// Correct top position of card because they have to occupy the same space
// during animation.
var n = item.getEl();
n.setStyle({
position: 'absolute',
top: this.container.getLayoutTarget().getPadding('t') + 'px'
});
if (this.activeItem) {
this.activeItem.getEl().fadeOut({
useDisplay:true,
callback: Ext.Component.prototype.hide,
scope: this.activeItem
});
}
this.activeItem = item;
item.show();
this.container.doLayout();
n.fadeIn({
callback: function() {
n.setStyle({
position: ''
});
}
});
Ext.Fx.sequenceFx();
} else {
if(this.activeItem){
this.activeItem.hide();
}
this.activeItem = item;
item.show();
this.container.doLayout();
}
}
}
});
jay@moduscreate.com
18 Sep 2008, 4:04 AM
I experimented a while back with fades for masks. It's a great idea if the objects are rendered.
http://tdg-i.com/img/screencasts/2008-03-13_1656.swf
Very nice.
One thing that is strange, is that with IE, after I cycle through my cards once, and then start cycling backwards, the animation quits working. Works fine in FF3, Chrome(beta).
Here (http://clan.homelinux.com:8080/ext-samples/cardlayout.html)
gugman
18 Sep 2008, 9:46 PM
This cross-fade CardLayout is fantastic. Thank you Animal.
To get this to work in IE, 'useDisplay:true' needs to be added to the fadeOut config:
this.activeItem.getEl().fadeOut({
useDisplay:true,
callback: Ext.Component.prototype.hide,
scope: this.activeItem
});
Animal
18 Sep 2008, 11:50 PM
Thanks for that hint. I've updated the code in post #1.
The fadeIn/fadeOut will work adding useDisplay: true
However, now when you bounce back and forth between the last two panels in my little test, the accordion looses any of the panels that are collapsed at the bottom. You do see them flash for a bit when leaving the accordion card going to the slider card. But when you go back to the accordion card, the panel headers (to expand) do not show up until you collapse the displayed header.
Still very nice effect.
Animal
19 Sep 2008, 4:51 AM
OK, try the latest code. It now uses
n.fadeIn({
callback: function() {
n.setStyle({
position: '',
});
}
});
To fade the new Panel in which restores positioning to the default.
Appears to have not made a difference.
I will try to look at it in more detail this weekend (real work getting in the way of fun).
Well, was a busy weekend, and did not get to spend much time on this. I did have to clean up the demo a bit (was a bunch of cut and paste examples), and that helped some. However in IE, when paging backwards, it still has a problem (meaning the fade Out/In does not work).
Also, I had to change two lines: this.container.doLayout(); to: this.layout();
With those and your previous changes, everything works perfectly in FF, Chorme (and I imagine others). Only IE is behaving strangely. :-?
gugman
22 Sep 2008, 4:51 PM
CKR:
I have run into this before with IE. IE requires an element to be positioned in order for filter/opacity to work correctly. Setting position to: ' ' breaks it in IE. See possible fix below which I tested on your sample.
Animal:
I tried setting position to 'relative' on the fadeIn callback and that seems to work:
n.fadeIn({
callback: function() {
n.setStyle({
position: 'relative',
});
}
});
More information on this and other IE related Opacity/Positioning bugs:
http://www.makemineatriple.com/2007/05/opacity_text_issues/
http://joseph.randomnetworks.com/archives/2006/08/16/css-opacity-in-internet-explorer-ie/
Great! Everything appears to be working in IE, FF, Chrome (only ones I tested).
I will leave the demo (http://clan.homelinux.com:8080/ext-samples/cardlayout.html) up for awhile incase others wish to see. Thanks Animal! Thanks Gugman!
Here was what I finally ended up with code wise:
Ext.override(Ext.layout.CardLayout, {
setActiveItem : function(item){
item = this.container.getComponent(item);
if(this.activeItem != item){
if (item.rendered && this.animate) {
Ext.Fx.syncFx();
if (this.activeItem) {
// Correct top position of card because they have to occupy the same space
// during animation.
var n = item.getEl();
n.setStyle({
position: 'absolute',
top: this.container.getLayoutTarget().getPadding('t') + 'px'
});
this.activeItem.getEl().fadeOut({
useDisplay: true,
callback: Ext.Component.prototype.hide,
scope: this.activeItem
});
}
this.activeItem = item;
item.show();
this.layout();
n.fadeIn({
callback: function() {
n.setStyle({
position: 'relative'
});
}
});
Ext.Fx.sequenceFx();
} else {
if(this.activeItem){
this.activeItem.hide();
}
this.activeItem = item;
item.show();
this.layout();
}
}
}
});
vishalg
6 Nov 2008, 2:07 PM
n.setStyle({
position: '',
});
should remove ',' to use in IE.
How hard would it be to support different effects ?
Thanks for this extension animal.
Ya that was corrected in my post.
Also check here (http://extjs.com/forum/showthread.php?p=235953#post235953) there is a demo in that post.
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.