An HTML Document typically consists of a lot of html markup. When the browser loads your html document, each tag in your markup get translated into an HTMLElement and the browser builds a Document Object Model (DOM) tree of the markup. This DOM tree is saved in the browser's global scope in a variable called document. This document variable holds a reference to every piece of markup which has been loaded on the page.
The document object provides an important method named getElementById. This method allows you to retrieve the underlying HTMLElement in any browser. However, you should be mindful that there are many differences among browsers when directly manipulating the DOM. Ext Core implements a class named Ext.Element which wraps around typical HTMLElement's providing you cross-browser support.
Ext.Element has the most methods out of any class in the Ext Core library. These methods can be categorized as follows:
You can use the method Ext.get to create an instance of an Ext.Element which wraps around any HTMLElement. For example, if your markup had an element with an id of 'myElementId' you could retrieve it like this.
var el = Ext.get('myElementId');
Using Firebug, try executing the following code. Observe the methods exposed by Ext.Element. Remember that because you are looking at the raw JS Object, both public as well as private methods are visible. When in doubt, consult the API documentation.
var el = Ext.get('myElementId');
console.dir(el);
console.dir is a method provided by Firebug which will dump out the contents of an object in an easily viewable format. It also allows you to expand and collapse sub-objects which have additional properties. Properties are shown in the color black. Methods/Functions are green; constructors or classes in red.
Now let's try interacting with the paragraph above which has an id of myElementId.
var el = Ext.get('myElementId'); el.addClass('error');
After executing this code, the font color in the paragraph above will change to red. This page has a CSS rule which changes all elements with a class of error to the color red. The CSS rule looks like this:
.error {
color: red;
}
The next section on Ext.Element (CSS Classes & Styling) will cover many ways to interact with with your elements' CSS classes and styling.
The Flyweight Design Pattern is a pattern used to minimize memory usage by creating a single global object and then re-using that object over and over again. Ext creates a global Ext.Element to use as the Flyweight when it starts up. This global flyweight instance can then be used to target any node in the Dom. To access this flyweight object you can use the Ext.fly method. Those new to Ext often express confusion about whether to use Ext.get or Ext.fly:
Whenever a reference to an Ext.Element is required to be saved for later use, use the Ext.get method. For times when you don't need to store a reference to the element, you can use the shared flyweight Ext.Element across the library. To access this flyweight object, use the method Ext.fly(elementId).
Let's remove the error class from the paragraph above.
Ext.fly('myElementId').removeClass('error');
When this code was executed, Ext was able to re-use the existing shared flyweight object and did not have to instantiate a brand new instance of an Ext.Element. The fly method is appropriate in situations executing a single, one-lined, atomic operation. You never want to try to store a reference to the flyweight object, since it is subject to change by some other snippet of code. For an example, let's take a look at the following example.
var el = Ext.fly('foo'); Ext.fly('bar').frame(); el.addClass('error');
frame is a highlighting effect that is included in the animation package of Ext.Element. What do you think the results would be?
The answer is that the element with an id of bar will have the frame effect applied to it and then immediately after it will also have the CSS class of error applied to it. Nothing will happen to the element with an id of foo, because the reference el points to the global flyweight which was overwritten when we used the frame effect on bar. If you did not expect this, re-read the section about flyweights as it is an important concept if you wish to use the Ext.fly method.
var el1 = Ext.get('elId'); // takes an element id var el2 = Ext.get(el1); // takes an Ext.Element var el3 = Ext.get(el1.dom); // takes an HTMLElement
// We want to perform only one discrete action on this element. Ext.fly('elId').hide();
// gets dom node based on id var elDom = Ext.getDom('elId'); // gets dom node based on the dom node var elDom1 = Ext.getDom(elDom); // If we don't know if we are working with an // Ext.Element or a dom node use Ext.getDom function(el){ var dom = Ext.getDom(el); // do something with the dom node }
We have learned about markup, how that relates to the document and the methods that Ext Core provides making it easy to retrieve that data. What about the layout of the document though? How do we manipulate the layout and styling of the document? The answer is to use Cascading Style Sheets (CSS) styling. CSS is the language by which we can control layout and visual information about our page. Ext Core makes it really easy to manipulate the style of elements in the document through classes or by modifying styles directly.
<style type="text/css"> myCls { color: #F00; } </style> ... <div type="myCls">Hello</div>In the example above the class 'myCls' is applied to the div giving the text 'Hello' a visual color of red (#F00).
Now that we have already learned about firebug, take a look some more of the wonderful tools that it has to offer us. Right click on any element in the page
and choose "Inspect Element". Now in firebug we can see the dom tree and where that element is located. If you look to the right of that
tree you will see a panel with all of the styles applied to that element.
If you're not yet familiar with using FireBug, pause now and learn all about it -- it's the oscilloscope of web-development. Inspect-element comes in handy for changing styles on an existing site or creating and debugging styles on a new site.
So lets explore the methods that Ext Core provides to make css modifications easier for you.
Ext.fly('elId').addClass('myCls'); // adds the class 'myCls' to the element
// add the class 'myCls' to the element and remove that same class from // all sibilings. Ext.fly('elId').radioClass('myCls');
Ext.fly('elId').removeClass('myCls'); // remove the class from the element
Ext.fly('elId').toggleClass('myCls'); // the class is added Ext.fly('elId').toggleClass('myCls'); // the class is removed Ext.fly('elId').toggleClass('myCls'); // the class is added again
if (Ext.fly('elId').hasClass('myCls')) { // it has the class }
Ext.fly('elId').replaceClass('myClsA', 'myClsB');
var color = Ext.fly('elId').getStyle('color'); var zIndx = Ext.fly('elId').getStyle('z-index'); var fntFmly = Ext.fly('elId').getStyle('font-family'); // ... etc.
Ext.fly('elId').setStyle('color', '#FFFFFF'); Ext.fly('elId').setStyle('z-index', 10); Ext.fly('elId').setStyle({ display : 'block', overflow : 'hidden', cursor : 'pointer' }); // animate the transition of color Ext.fly('elId').setStyle('color', '#FFFFFF', true); // animate the transition of color with a duration of .75 seconds Ext.fly('elId').setStyle('color', '#FFFFFF', {duration: .75}); // ... etc.
Ext.fly('elId').getColor('background-color'); Ext.fly('elId').getColor('color'); Ext.fly('elId').getColor('border-color'); // ... etc.
Ext.fly('elId').setOpacity(.5); Ext.fly('elId').setOpacity(.45, true); // animates // animates with a duration of half a second Ext.fly('elId').setOpacity(.45, {duration: .5});
Ext.fly('elId').clearOpacity();
Frequently we want to navigate around the dom tree from any given position that we are working in. Ext Core provides many useful cross browser methods that give you trememndous power in traversing up, down and all around the dom. Again CSS comes to the rescue when we want to perform complex navigations rather easily. The use of CSS3 selectors has a powerful application in this domain. Take the following markup:
<style type="text/css"> .red { color: #F00; } </style> ... <div id='elId'> <ul> <li>a-one</li> <li>a-two</li> <li>a-three</li> <li>a-four</li> </ul> <ul> <li>b-one</li> <li>b-two</li> <li>b-three</li> </ul> </div>Now say you have a requirement to make every other list item have red text. Ext Core allows you to solve this elegantly with the following one-liner.
Ext.fly('elId').select('li:nth-child(2n)').addClass('red');Here is the result:
var el = Ext.get('elId'); if (el.is('p.myCls')) { // do something }
Ext.fly('elId').findParent('div'); // returns a dom node Ext.fly('elId').findParent('div', 4); // looks up 4 parent nodes Ext.fly('elId').findParent('div', null, true); // returns an Ext.Element
Ext.fly('elId').findParentNode('div');
Ext.fly('elId').up('div'); Ext.fly('elId').up('div', 5); // only looks up 5 parents
// CompositeElement of results is returned Ext.fly('elId').select('div:nth-child(2)'); // Array of elements is returned Ext.fly('elId').select('div:nth-child(2)', true); // Entire document is searched Ext.select('div:nth-child(2)');
Ext.query('div:nth-child(2)'); // Array of dom nodes that matched the selector
Ext.fly('elId').child('p.highlight'); // returns an Ext.Element Ext.fly('elId').child('p.highlight', true); // returns a dom node
Ext.fly('elId').down('span'); // returns an Ext.Element Ext.fly('elId').down('span', true); // returns a dom node
// grabs the parent node as and Ext.Element Ext.fly('elId').parent(); // grabs the parent node as a dom node Ext.fly('elId').parent("", true); // grabs the first parent that is a div, returns Ext.Element Ext.fly('elId').parent("div");
// grabs the next sibling node as and Ext.Element Ext.fly('elId').next(); // grabs the next sibling node as a dom node Ext.fly('elId').next("", true); // grabs the next sibling node that is a div, returns Ext.Element Ext.fly('elId').next("div");
// grabs the previous sibling node as and Ext.Element Ext.fly('elId').prev(); // grabs the previous sibling node as a dom node Ext.fly('elId').prev("", true); // grabs the previous sibling node that is a div, returns Ext.Element Ext.fly('elId').prev("div");
// grabs the first sibling node as and Ext.Element Ext.fly('elId').first(); // grabs the first sibling node as a dom node Ext.fly('elId').first("", true); // grabs the first sibling node that is a div, returns Ext.Element Ext.fly('elId').first("div");
// grabs the last sibling node as and Ext.Element Ext.fly('elId').last(); // grabs the last sibling node as a dom node Ext.fly('elId').last("", true); // grabs the last sibling node that is a div, returns Ext.Element Ext.fly('elId').last("div");
In a dynamic page one of the most frequent tasks is to create or remove elements in the DOM. Due to inconsistencies between browsers this can prove to be a challenging task. Ext Core provides a stong API that abstracts these cross browser inconsistencies and is internally optimized for efficiency. We can easily add, remove or replace nodes in the Dom tree at any position we want relative to siblings and parents using Ext Core's Dom Manipulation API. Let's take a look for ourselves -- observe the following markup:
<div id='elId'> <p>paragraph one</p> <p>paragraph two</p> <p>paragraph three</p> </div>Here is a screenshot of the markup:
Ext.fly('elId').insertFirst({ tag: 'p', html: 'Hi I am the new first child' });Now we can see that our node was inserted:
var el = Ext.get('elId1'); // append the dom node with this id. Ext.fly('elId').appendChild('elId2'); // append an Ext.Element Ext.fly('elId').appendChild(el); // append the result of an array of selectors Ext.fly('elId').appendChild(['elId2','elId3']); // append a straight dom node Ext.fly('elId').appendChild(el.dom); // append a CompositeElement of all divs Ext.fly('elId').appendChild(Ext.select('div'));
var el = Ext.get('elId1'); Ext.fly('elId').appendTo('elId2'); // append to the dom node with this id. Ext.fly('elId').appendTo(el); // append to the Ext.Element el
var el = Ext.get('elId1'); // inserts before the dom node with this id. Ext.fly('elId').insertBefore('elId2'); // inserts before the Ext.Element el Ext.fly('elId').insertBefore(el);
var el = Ext.get('elId1'); // inserts after the dom node with this id. Ext.fly('elId').insertAfter('elId2'); // inserts after the Ext.Element el Ext.fly('elId').insertAfter(el);
var el = Ext.get('elId1'); // inserts the dom node with this id as the first child. Ext.fly('elId').insertFirst('elId2'); // inserts the Ext.Element el as the first child Ext.fly('elId').insertFirst(el); // creates a new node with the DomHelper config and inserts // the result as the first child. Ext.fly('elId').insertFirst({ tag: 'p', cls: 'myCls', html: 'Hi I am the new first child' });
var el = Ext.get('elId1'); // replaces the element with id 'elId2' with 'elId'. Ext.fly('elId').replace('elId2'); // replaces the element with id 'elId1' with 'elId' Ext.fly('elId').replace(el);
var el = Ext.get('elId1'); Ext.fly('elId').replaceWith('elId2'); // replaces 'elId' with 'elId2'. Ext.fly('elId').replaceWith(el); // replaces 'elId' with 'elId1' // creates a new node with the DomHelper config // and replaces 'elId' with this node. Ext.fly('elId').replaceWith({ tag: 'p', cls: 'myCls', html: 'Hi I have replaced elId' });
.insertFirst({
tag: 'p',
html: 'Hi I am the new first child'
});
You may have wondered what the 1st argument to insertFirst is. This is a DomHelper config which represents the markup to be created. DomHelper configs support many properties for specifying child nodes, such as html fragments and DomNode attributes (css classes, url, src, id, etc). Here are some of the API's available on Ext.Element that allow you to interact directly with Ext.DomHelper:
var el = Ext.get('elId'); var dhConfig = { tag: 'p', cls: 'myCls', html: 'Hi I have replaced elId' }; // creates a new node and appends it to 'elId'. el.createChild(dhConfig); // creates a new node and inserts before el's first child. el.createChild(dhConfig, el.first());
Ext.fly('elId').wrap(); // wraps elId with a div // wraps elId with the newly create element Ext.fly('elId').wrap({ tag: 'p', cls: 'myCls', html: 'Hi I have replaced elId' });
Html fragments are just what they sound like, fragments of html markup. Ext Core provides the ability to modify the dom with html fragments, allowing you to focus upon just those fragments of markup that you intend to modify the dom with, freeing you from browser implementation and performance worries. Ext Core does all of that for you -- all you need to do is provide the markup. For example, given the following markup:
<div id='elId'> <li>one</li> <li>two</li> <li>three</li> <li>four</li> </div>
What do you think the following Ext Core code will do?
Ext.fly('elId').insertHtml('beforeBegin', '<p>Hi</p>')
Lets take a look at the markup afterward:
<p>Hi</p> <div id='elId'> <li>one</li> <li>two</li> <li>three</li> <li>four</li> </div>Suprised? That's because we are able to specify the relative position where we want this markup applied. We specified 'beforeBegin'. What about this:
Ext.fly('elId').insertHtml('afterBegin', '<p>Hi</p>')Lets take a look:
<div id='elId'> <p>Hi</p> <li>one</li> <li>two</li> <li>three</li> <li>four</li> </div>Now we will use 'beforeEnd'.
Ext.fly('elId').insertHtml('beforeEnd', '<p>Hi</p>')Lets take a look:
<div id='elId'> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <p>Hi</p> </div>And finally lets look at 'afterEnd'.
Ext.fly('elId').insertHtml('beforeEnd', '<p>Hi</p>')Lets take a look:
<div id='elId'> <li>one</li> <li>two</li> <li>three</li> <li>four</li> </div> <p>Hi</p>The following API is yeaprovided for you to work with html fragments.
Ext.fly('elId').insertHtml( 'beforeBegin', '<p><a href="anotherpage.html'>click me</a></p>' ); // returns dom node Ext.fly('elId').insertHtml( 'beforeBegin', '<p><a href="anotherpage.html'>click me</a></p>', true ); // returns Ext.Element
Ext.fly('elId').remove(); // elId is removed from the dom and from cache
Ext.removeNode(node); // node (HTMLElement) is removed from the dom
Ext Core includes a powerful Ajax API. Ajax will be covered in greater detail in later sections but here's a brief overview of the present API in Ext Core:
Ext.fly('elId').load({url: 'serverSide.php'})
var updr = Ext.fly('elId').getUpdater(); updr.update({ url: 'http://myserver.com/index.php', params: { param1: "foo", param2: "bar" } });
Event handling poses one of the most troublesome differences among the browsers. Ext Core abstracts the differences you would encounter to achieve cross-browser event handling. If you were to use each browser's native event handling mechanism you need to use different methods to register and unregister events in addition to a myriad of other frustrating inconsistencies.
Ext Core provides a rich event model which frees one from these differences by using a single clean, consistent interface. Just as Ext.Element wraps around a native Dom node, Ext Core will also wrap the browser's native event-object with an instance of Ext.EventObject. Ext.EventObject normalizes cross-browser differences, such as which mouse button is clicked, keys pressed, mechanisms to stop event-propagation along with a method to prevent default actions from taking place.
To tie an event handler to an element on the page we will use the on method of Ext.Element. The on method is a preferred shorthand for addListener. The first argument specifies which event to subscribe to and the second argument specifies the function to run when that event occurs.
Ext.fly('myEl').on('click', function(e, t) {
// perform an action on click of myEl
// e is an Ext.EventObject describing what occured
// t is the target HTMLElement
});
Ext Core normalizes the arguments of all Dom events. The event handler which is tied to the event will always receive a normalized event object (Ext.EventObject) and the target HTMLElement.
Let's take a look at the API provided for Event Handling:
var el = Ext.get('elId'); el.on('click', function(e,t) { // e is a normalized event object (Ext.EventObject) // t the target that was clicked, this is an Ext.Element. // this also points to t. });
var el = Ext.get('elId'); el.un('click', this.handlerFn); // or el.removeListener('click', this.handlerFn);
// e is not a standard event object, it is a Ext.EventObject function handleClick(e){ e.preventDefault(); var target = e.getTarget(); ... } var myDiv = Ext.get('myDiv'); myDiv.on("click", handleClick); //or Ext.EventManager.on('myDiv', 'click', handleClick); Ext.EventManager.addListener('myDiv', 'click', handleClick);
Ext Core has several convenience configurations for more advanced event handling techniques such as event delegation, buffering, and delays.
Rather than registering an event handler for each element in a group of elements, register it once in a container element taking advantage of the bubbling phase in the event life-cycle and centralize the event-handling at the container level.This doesn't mean that you want to register one global handler on the body element, as any action on the page that fired an event would bubble up to that handler and probably have the reverse effect, actually degrading performance. This technique is extremely useful in situations like a drop-down, a calendar, etc. Anywhere you have a group of elements that can be directly or almost directly contained by a container element. Lets take a look:
<ul id='actions'> <li id='btn-edit'></li> <li id='btn-delete'></li> <li id='btn-cancel'></li> </ul>Instead of registering a handler directly upon each list item as follows:
Ext.fly('btn-edit').on('click, function(e,t) { // handle the event }); Ext.fly('btn-delete').on('click, function(e,t) { // handle the event }); Ext.fly('btn-cancel').on('click, function(e,t) { // handle the event });To use the event delegation technique instead, registering just one handler on the container along with accompanying logic:
Ext.fly('actions').on('click, function(e,t) { switch(t.id) { case ''btn-edit': // handle the event break; case 'btn-delete': // handle the event break; case 'btn-cancel': // handle the event break; } });Because events bubble up the dom hierarchy, they will reach the handler that we registered on the 'actions' div. We then use a simple switch to execute the required code. This approach scales well because we can add many different child elements and still maintain a single event handler.
el.on('click', function(e,t) { // handle click }, this, { // will filter target to be a descendant with the class 'clickable' delegate: '.clickable' });
// handles when the mouse enters the element function enter(e,t){ t.toggleClass('red'); } // handles when the mouse leaves the element function leave(e,t){ t.toggleClass('red'); } // subscribe to the hover el.hover(over, out);
el.removeAllListeners();
el.on('click', function(e,t) { // handle click }, this, { single: true // will remove the event after its first firing. });
el.on('click', function(e,t) { // handle click }, this, { buffer: 1000 // will delay and buffer the firing of //this event after its initial fire 1000 miliseconds (or 1 second). });
el.on('click', function(e,t) { // handle click }, this, { // will delay the firing of this event after its initial // fire 1000 miliseconds (or 1 second). delay: 1000 });
el.on('click', function(e,t) { // handle click }, this, { // only handles the event when it has bubbled up to the first 'div'. target: el.up('div') });
Often we need to retrieve or change the dimensions of some particular element on a page. Once again, Ext Core abstracts dimensioning through a clean API. Most of the setter-methods accept animation configurations or a straight boolean true to animate the action. Let's take a look:
// changes the height to 200px and animates with default configuration Ext.fly('elId').setHeight(200, true); // changes the height to 150px and animates with a custom configuration Ext.fly('elId').setHeight(150, { duration : .5, // animation will have a duration of .5 seconds // will change the content to "finished" callback: function(){ this.update("finished"); } });Pull up firebug, inspect and element (right click and then click on 'Inspect Element') and take a look at the right panel and click on "layout". You should see something like this:
var dimSz = Ext.get('dim-sizing'); var padding = dimSz.getPadding('lrtb'); // has value of 0px var border = dimSz.getBorderWidth('lrtb'); // has value of 0px var height = dimSz.getHeight(); // has value of 1691px var width = dimSz.getWidth(); // has value of 895pxGrab this code and run it in firebug to see for yourself. In fact go a step further and try using the setters to modify the height and width and see what happens to the box in the firebug layout panel. (NOTE: if your height and width are different from the image, that is because of the dimensions of your browser. If you navigate of inspect that element in you actual browser the outputs should match.)
var ht = Ext.fly('elId').getHeight();
var wd = Ext.fly('elId').getWidth();
Ext.fly('elId').setHeight();
Ext.fly('elId').setWidth();
var bdr_wd = Ext.fly('elId').getBorderWidth('lr');
var padding = Ext.fly('elId').getPadding('lr');
Ext.fly('elId').clip();
Ext.fly('elId').unclip();
if (Ext.isBorderBox) {
// do something
}
Through Ext Core's positioning API it's a snap to get and set all aspects of an element's position across all browsers. Similar to the dimension API, most of the setters support animations, either through a boolean true (for defaults) or by passing an object-literal configuration object as the second argument. Lets see an example of what this looks like: Lets see an example of what this looks like:
// changes the x-coord to 75px and animates with a custom configuration Ext.fly('elId').setX(75, { duration : .5, // animation will have a duration of .5 seconds // will change the content to "finished" callback: function(){ this.update("finished"); } });
var elX = Ext.fly('elId').getX()
var elY = Ext.fly('elId').getY()
var elXY = Ext.fly('elId').getXY() // elXY is an array
Ext.fly('elId').setX(10)
Ext.fly('elId').setY(10)
Ext.fly('elId').setXY([20,10])
var elOffsets = Ext.fly('elId').getOffsetsTo(anotherEl);
var elLeft = Ext.fly('elId').getLeft();
var elRight = Ext.fly('elId').getRight();
var elTop = Ext.fly('elId').getTop();
var elBottom = Ext.fly('elId').getBottom();
Ext.fly('elId').setLeft(25)
Ext.fly('elId').setRight(15)
Ext.fly('elId').setTop(12)
Ext.fly('elId').setBottom(15)
Ext.fly('elId').setLocation(15,32)
Ext.fly('elId').moveTo(12,17)
Ext.fly('elId').position("relative")
Ext.fly('elId').clearPositioning() Ext.fly('elId').clearPositioning("top")
var pos = Ext.fly('elId').getPositioning()
Ext.fly('elId').setPositioning({ left: 'static', right: 'auto' })
// {left:translX, top: translY} var points = Ext.fly('elId').translatePoints(15,18);
Ext Core has animation plugins available that give you a robust set of preconfigured animations that are alredy applied as methods to Ext.Element so you can do cool things like this:
Ext.fly('slideEl').slideOut('r');Copy the above code, run it in FireBug and see what happens. You will see below that Ext has a full set of animations already built for you. Each animation takes a configuration object literal making it very customizable if you need more than the default behavior. Perhaps you want to add your own callback function to fire upon completion of the animation:
Ext.fly('slideEl').slideOut('r', { callback : function(){ alert('Finished sliding the element out'); } });So you can see there are some really powerful animations here.
| Value | Description |
|---|---|
| tl | The top left corner |
| t | The center of the top edge |
| tr | The top right corner |
| l | The center of the left edge |
| r | The center of the right edge |
| bl | The bottom left corner |
| b | The center of the bottom edge |
| br | The bottom right corner |
// default: slide the element in from the top el.slideIn(); // default: slide the element out from the bottom el.slideOut(); // common config options shown with default values el.slideIn('t', { easing: 'easeOut', duration: .5 }); el.slideOut('t', { easing: 'easeOut', duration: .5, remove: false, useDisplay: false });
// default el.puff(); // common config options shown with default value el.puff({ easing: 'easeOut', duration: .5, remove: false, useDisplay: false });
// default el.switchOff(); // all config options shown with default values el.switchOff({ easing: 'easeIn', duration: .3, remove: false, useDisplay: false });
// default: highlight background to yellow el.highlight(); // common config options shown with default values el.highlight("ffff9c", { //can be any valid CSS property (attribute) that supports a color value attr: "background-color", endColor: (current color) or "ffffff", easing: 'easeIn', duration: 1 });
// default: a single light blue ripple el.frame(); // common config options shown with default values el.frame("C3DAF9", 1, { duration: 1 //duration of each individual ripple. // Note: Easing is not configurable and will be ignored if included });
el.pause(1);
// default: fade in from opacity 0 to 100% el.fadeIn(); el.fadeOut(); // common config options shown with default values el.fadeIn({ endOpacity: 1, //can be any value between 0 and 1 (e.g. .5) easing: 'easeOut', duration: .5 }); el.fadeOut({ endOpacity: 0, //can be any value between 0 and 1 (e.g. .5) easing: 'easeOut', duration: .5, remove: false, useDisplay: false });
// change height and width to 100x100 pixels el.scale(100, 100); // common config options shown with default values. The height and width will // default to the element's existing values if passed as null. el.scale( [element's width], [element's height], { easing: 'easeOut', duration: .35 } );
// slide the element horizontally to x position 200 while changing // the height and opacity el.shift({ x: 200, height: 50, opacity: .8 }); // common config options shown with default values. el.shift({ width: [element's width], height: [element's height], x: [element's x position], y: [element's y position], opacity: [element's opacity], easing: 'easeOut', duration: .35 });
// default: slide the element downward while fading out el.ghost(); // common config options shown with default values el.ghost('b', { easing: 'easeOut', duration: .5, remove: false, useDisplay: false });
var el = Ext.get('complexEl') el.animate({ borderWidth: {to: 3, from: 0}, opacity: {to: .3, from: 1}, height: {to: 50, from: el.getHeight()}, width: {to: 300, from: el.getWidth()} });
The following are useful Ext.Element methods which don't fit in the previous sections but bear mentioning.
el.focus();
el.blur();
el.getValue(); el.getValue(true); // parses the value as a number
if (Ext.isBorderBox) { }
el.getAttributeNS("","name");