YUI Library Home

YUI Library Examples: Container Family: Using ContainerEffect Transitions

Container Family: Using ContainerEffect Transitions

The Container Family of controls, including Overlay and all of its subclasses (Panel, Tooltip, Dialog, SimpleDialog), can implement built-in transition effects using the effect property and the ContainerEffect object. This example demonstrates the fade and slide transitions provided with Container.

Use the buttons below to show and hide Overlays, noting their transition treatments as they appear and disappear.

overlay1 (fade in):
overlay2 (slide in):
overlay3 (fade and slide):

Using Transition Effects via the "effect" Property and the ContainerEffect Object

The ContainerEffect class allows Overlay and its subclasses to be configured with transitional animations that are activated when an Overlay is shown or hidden. For instance, an Overlay can easily be made to fade in and out, or slide in and out of the viewport when the visibility of the Overlay is changed. The effect property takes an object literal or an array of object literals which define two fields: the predefined effect to use, and the duration of the animation.

In this tutorial, we will create three Overlays and set them up to use the effect property in different ways. First, we will create a simple Overlay that fades in and out. The built-in ContainerEffect constant used for the fade animation is YAHOO.widget.ContainerEffect.FADE, so we will specify that as the "effect" property of our object literal. The duration should be 0.25 seconds, specified by the "duration" property of the literal:

1YAHOO.example.container.overlay1 =  
2    new YAHOO.widget.Overlay("overlay1", { xy:[150,100],  
3       visible:false,  
4       zIndex:1000, 
5       width:"300px"
6       effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} } ); 
view plain | print | ?

Our second Overlay shows how you can use ContainerEffect's "SLIDE" constant. This Overlay looks exactly like the first one, but we will replace "FADE" with "SLIDE":

1YAHOO.example.container.overlay2 =  
2    new YAHOO.widget.Overlay("overlay2", { xy:[250,200],  
3       visible:false,  
4       zIndex:1000, 
5       width:"300px"
6       effect:{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.25} } ); 
view plain | print | ?

Effects can also be specified as an array of transitions that will all execute simultaneously. For instance, an Overlay can be made to fade and slide in at the same time. When using the ContainerEffect class to configure your Overlay, chaining is not supported, so all animations will always execute at the same time. However, if you need to chain animations, the Animation utility allows you to do this using events. We will set up the third and final Overlay with an array of effects:

1YAHOO.example.container.overlay3 =  
2    new YAHOO.widget.Overlay("overlay3", { xy:[350,300],  
3       visible:false,  
4       zIndex:1000, 
5       width:"300px"
6       effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, 
7               {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}] } ); 
view plain | print | ?

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

YUI Logger Output:

Logger Console

INFO 1389ms (+0) 1:32:55 AM:

Config

Firing Config event: iframe=false

INFO 1389ms (+0) 1:32:55 AM:

Config

setProperty: xy=350,100

INFO 1389ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1389ms (+0) 1:32:55 AM:

Config

setProperty: x=350

INFO 1389ms (+0) 1:32:55 AM:

Config

Firing Config event: iframe=false

INFO 1389ms (+0) 1:32:55 AM:

Config

setProperty: xy=350,100

INFO 1389ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1389ms (+1) 1:32:55 AM:

Config

setProperty: x=350

INFO 1388ms (+0) 1:32:55 AM:

Config

Firing Config event: iframe=false

INFO 1388ms (+0) 1:32:55 AM:

Config

setProperty: xy=350,100

INFO 1388ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1388ms (+7) 1:32:55 AM:

Config

setProperty: x=350

INFO 1381ms (+0) 1:32:55 AM:

Config

setProperty: zindex=1000

INFO 1381ms (+0) 1:32:55 AM:

Config

Firing Config event: zindex=1000

INFO 1381ms (+0) 1:32:55 AM:

Config

Firing Config event: iframe=false

INFO 1381ms (+0) 1:32:55 AM:

Config

Config event queue: iframe=false, zindex=1000,

INFO 1381ms (+0) 1:32:55 AM:

Config

queueProperty: iframe=undefined

INFO 1381ms (+0) 1:32:55 AM:

Config

setProperty: xy=350,100

INFO 1381ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1381ms (+0) 1:32:55 AM:

Config

setProperty: x=350

INFO 1381ms (+0) 1:32:55 AM:

Config

Firing Config event: y=100

INFO 1381ms (+0) 1:32:55 AM:

Config

Config event queue: y=100, iframe=false, zindex=1000,

INFO 1381ms (+0) 1:32:55 AM:

Config

queueProperty: iframe=undefined

INFO 1381ms (+1) 1:32:55 AM:

Config

setProperty: xy=350,100

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: x=350

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: x=350

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: visible=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: effect=[object Object],[object Object]

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: fixedcenter=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: fixedcenter=false, effect=[object Object],[object Object], visible=false, x=350, y=100, iframe=false, zindex=1000,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: iframe=undefined

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: width=300px

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: width=300px, fixedcenter=false, effect=[object Object],[object Object], visible=false, x=350, y=100, iframe=false, zindex=1000,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: iframe=undefined

IFRA 1380ms (+0) 1:32:55 AM:

global

xy: 350,100

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: width=300px, fixedcenter=false, zindex=1000, effect=[object Object],[object Object], visible=false, x=350, y=100, iframe=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: y=100

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: y=100

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: width=300px, fixedcenter=false, zindex=1000, effect=[object Object],[object Object], visible=false, x=350, iframe=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: x=350

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: x=350

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: xy=350,100

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: constraintoviewport=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: preventcontextoverlap=false

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: autofillheight=body

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: autofillheight=body

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: appendtodocumentbody=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Firing Config event: monitorresize=true

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, autofillheight=body, preventcontextoverlap=false, constraintoviewport=false, xy=350,100, width=300px, fixedcenter=false, iframe=false, zindex=1000, effect=[object Object],[object Object], visible=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: effect=[object Object],[object Object]

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, autofillheight=body, preventcontextoverlap=false, constraintoviewport=false, xy=350,100, visible=false, width=300px, fixedcenter=false, iframe=false, zindex=1000,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: zindex=1000

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, autofillheight=body, zindex=null, preventcontextoverlap=false, constraintoviewport=false, xy=350,100, visible=false, width=300px, fixedcenter=false, iframe=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: width=300px

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, autofillheight=body, zindex=null, preventcontextoverlap=false, constraintoviewport=false, xy=350,100, iframe=false, visible=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: visible=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body, zindex=null, preventcontextoverlap=false, constraintoviewport=false, xy=350,100, iframe=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: xy=350,100

INFO 1380ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body, iframe=false, zindex=null, preventcontextoverlap=false, constraintoviewport=false,

INFO 1380ms (+0) 1:32:55 AM:

Config

queueProperty: preventcontextoverlap=false

INFO 1380ms (+0) 1:32:55 AM:

Config

setProperty: preventcontextoverlap=false

INFO 1380ms (+0) 1:32:55 AM:

Config

Added property: preventcontextoverlap

INFO 1380ms (+1) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body, constraintoviewport=false, iframe=false, zindex=null,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: iframe=false

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: iframe=false

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: iframe

INFO 1379ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body, zindex=null, constraintoviewport=false,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: constraintoviewport=false

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: constraintoviewport=false

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: constraintoviewport

INFO 1379ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body, zindex=null,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: zindex=null

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: zindex=null

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: zindex

INFO 1379ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true, autofillheight=body,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: autofillheight=body

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: autofillheight=body

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: autofillheight

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: height=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: height

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: width=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: width

INFO 1379ms (+0) 1:32:55 AM:

Config

Config event queue: monitorresize=true, appendtodocumentbody=false, fixedcenter=false, visible=true,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: fixedcenter=false

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: fixedcenter=false

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: fixedcenter

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: context=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: context

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: xy=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: xy

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: y=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: y

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: x=undefined

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: x

INFO 1379ms (+0) 1:32:55 AM:

Config

Config event queue: visible=true, monitorresize=true, appendtodocumentbody=false,

INFO 1379ms (+0) 1:32:55 AM:

Config

queueProperty: appendtodocumentbody=false

INFO 1379ms (+0) 1:32:55 AM:

Config

setProperty: appendtodocumentbody=false

INFO 1379ms (+0) 1:32:55 AM:

Config

Added property: appendtodocumentbody

INFO 1379ms (+1379) 1:32:55 AM:

Config

Config event queue: visible=true, monitorresize=true,

INFO 0ms (+0) 1:32:54 AM:

global

Logger initialized

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

Container Family Examples:

More Container Family Resources:

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings