Yahoo! Developer Network Home - Help

YDN Site Search

# 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 treatmens as they appear and disappear.

View example in new window.

overlay1 (fade in):
overlay2 (slide in):
overlay3 (fade and slide):
Overlay #1 from Markup
This is a Overlay that was marked up in the document.
End of Overlay #1
Overlay #2 from Markup
This is a Overlay that was marked up in the document.
End of Overlay #2
Overlay #3 from Markup
This is a Overlay that was marked up in the document.
End of Overlay #3

## 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:

YAHOO.example.container.overlay1 = new YAHOO.widget.Overlay("overlay1", { xy:[150,100], visible:false, zIndex:1000, width:"300px", effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} } );

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":

YAHOO.example.container.overlay2 = new YAHOO.widget.Overlay("overlay2", { xy:[250,200], visible:false, zIndex:1000, width:"300px", effect:{effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.25} } );

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:

YAHOO.example.container.overlay3 = new YAHOO.widget.Overlay("overlay3", { xy:[350,300], visible:false, zIndex:1000, width:"300px", effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, {effect:YAHOO.widget.ContainerEffect.SLIDE,duration:0.5}] } );

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Container Family Examples:

- The Module Control
- Creating and Positioning an Overlay
- Simple Tooltip Example
- One Tooltip, Many Context Elements
- Simple Panel Example
- Skinning a Panel with Custom CSS: Introduction
- Skinning a Panel with Custom CSS: Advanced
- Creating a Modal "Loading" Panel
- Creating a Resizable Panel
- Dialog Quickstart Example
- SimpleDialog Quickstart Example
- Using ContainerEffect Transitions
- Using the Overlay Manager to Manage Multiple Panels
- Implementing Container Keyboard Shortcuts with KeyListener
- Example of Color Picker Built in a Dialog via JavaScript (included with examples for Color Picker Control)
- Layout inside a resizable Panel (included with examples for Layout Manager (beta))
- Calendar inside a Container (included with examples for Calendar Control)
- Menu Buttons (included with examples for Button Control)
- Showing and Hiding Columns (included with examples for DataTable Control (beta))
- Split Buttons (included with examples for Button Control)
- Calendar Menu Button (included with examples for Button Control)
- Calendar Menu Button (included with examples for Button Control)
- Color Picker Button (included with examples for Button Control)
- Fixed Width Menu Button (included with examples for Button Control)
- OS-Style Programs Menu (included with examples for Menu Family)
- Application Menubar (included with examples for Menu Family)
- Slider Button (included with examples for Button Control)
- Complex Application (included with examples for Layout Manager (beta))

### More Container Family Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

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