This example uses the YUI Carousel Control to showcase a simple spotlight
example using its itemSelected
event. In this example, you can use arrow
keys to select items as well as click on an item to select it.
Though this functionality looks a little complicated, it is very easy to
implement. This is because the YUI Carousel Control handles the keyboard
event and the mouse click event for setting the selection. When an item is
selected, the YUI Carousel Control triggers an itemSelected
event. This
example subscribes to the itemSelected
event to display the selected
image in the spotlight.
Here we will use the YUI Carousel Control's itemSelected
event to display
the selected image.
This example has the following dependencies:
This example uses progressive enhancement; the Carousel is created from an ordered list.
We will add a container element where we can display the spotlight image.
We'll have only one CSS rule to set the height for the Carousel items.
Since we have the elements in place, we can invoke the Carousel's
constructor to create the widget. The Carousel's selectedItem
property
returns the index of the currently selected item. So, using that property
and the getElementForItem()
API, we can display the image of the selected item when the
Carousel is rendered.
Now, we can subscribe to the selectedItem
event that the Carousel exposes.
This event is triggered whenever an item is selected and it returns the
index of the selected item. With the index of the item, we can use the
Carousel's getElementForItem()
API to get the reference to the Carousel's item (an li
element in
our case).
Once the reference to the Carousel's item is obtained, it is straightforward to implement a function that extracts the image within it.
Note: Logging and debugging is currently turned off for this example.
Copyright © 2008 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings