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.
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:
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":
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:
Note: Logging and debugging is currently turned off for this example.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.