This example uses the YUI Carousel Control to showcase how to customize and display pagination information.
Here we will use the YUI Carousel Control's private pagination
configuration
setting to display customized pagination information.
This example has the following dependencies:
1 | <link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/2.9.0/build/carousel/assets/skins/sam/carousel.css"> |
2 | <script src="http://yui.yahooapis.com/2.9.0/build/yahoo/yahoo-dom-event.js"></script> |
3 | <script src="http://yui.yahooapis.com/2.9.0/build/element/element-min.js"></script> |
4 | <script src="http://yui.yahooapis.com/2.9.0/build/carousel/carousel-min.js"></script> |
view plain | print | ? |
This example uses progressive enhancement; the Carousel is built from an existing ordered list.
1 | <div id="container"> |
2 | <ol id="carousel"> |
3 | <li> |
4 | <img src="http://farm1.static.flickr.com/135/342099636_7b05b7cde5_s.jpg" |
5 | width="75" height="75"> |
6 | </li> |
7 | <li> |
8 | <img src="http://farm1.static.flickr.com/136/342099938_fdef3ca3b5_s.jpg" |
9 | width="75" height="75"> |
10 | </li> |
11 | <li> |
12 | <img src="http://farm1.static.flickr.com/147/342099522_3827eaa929_s.jpg" |
13 | width="75" height="75"> |
14 | </li> |
15 | <li> |
16 | <img src="http://farm1.static.flickr.com/143/342100011_ec4d338c71_s.jpg" |
17 | width="75" height="75"> |
18 | </li> |
19 | <li> |
20 | <img src="http://farm1.static.flickr.com/161/342100080_0fe4f9ccb0_s.jpg" |
21 | width="75" height="75"> |
22 | </li> |
23 | <li> |
24 | <img src="http://farm1.static.flickr.com/153/342100324_82589c0ebe_s.jpg" |
25 | width="75" height="75"> |
26 | </li> |
27 | <li> |
28 | <img src="http://farm1.static.flickr.com/147/342100376_d0336252a7_s.jpg" |
29 | width="75" height="75"> |
30 | </li> |
31 | <li> |
32 | <img src="http://farm1.static.flickr.com/156/342100472_b9bc985fa4_s.jpg" |
33 | width="75" height="75"> |
34 | </li> |
35 | <li> |
36 | <img src="http://farm1.static.flickr.com/133/342100566_39dae4698f_s.jpg" |
37 | width="75" height="75"> |
38 | </li> |
39 | <li> |
40 | <img src="http://farm1.static.flickr.com/69/213130158_0d1aa23576_d.jpg" |
41 | width="75" height="75"> |
42 | </li> |
43 | <li> |
44 | <img src="http://farm1.static.flickr.com/72/213128367_74b0a657c3_d.jpg" |
45 | width="75" height="75"> |
46 | </li> |
47 | <li> |
48 | <img src="http://farm1.static.flickr.com/98/213129707_1f40c509fa_d.jpg" |
49 | width="75" height="75"> |
50 | </li> |
51 | <li> |
52 | <img src="http://farm1.static.flickr.com/80/259391136_6fa405c7f6_s.jpg" |
53 | width="75" height="75"> |
54 | </li> |
55 | <li> |
56 | <img src="http://farm1.static.flickr.com/87/258609416_bf0d44b445_s.jpg" |
57 | width="75" height="75"> |
58 | </li> |
59 | <li> |
60 | <img src="http://farm1.static.flickr.com/119/259395209_66c773a072_s.jpg" |
61 | width="75" height="75"> |
62 | </li> |
63 | <li> |
64 | <img src="http://farm1.static.flickr.com/83/259399727_3d170d0445_s.jpg" |
65 | width="75" height="75"> |
66 | </li> |
67 | <li> |
68 | <img src="http://farm1.static.flickr.com/121/258614620_16eb6867f7_s.jpg" |
69 | width="75" height="75"> |
70 | </li> |
71 | <li> |
72 | <img src="http://farm1.static.flickr.com/108/259397333_3e4a3960bd_s.jpg" |
73 | width="75" height="75"> |
74 | </li> |
75 | </ol> |
76 | </div> |
view plain | print | ? |
Make sure all carousel items have a width and height.
1 | /* Always be sure to give your carousel items a width and a height */ |
2 | .yui-carousel-element li { |
3 | width: 75px; |
4 | height: 75px; |
5 | } |
6 | |
7 | .yui-carousel-element .yui-carousel-item-selected { |
8 | border:0; /* Override selected item's dashed border so it feels more like a photo album */ |
9 | } |
10 | |
11 | #container { |
12 | position: relative; |
13 | } |
14 | |
15 | .yui-carousel-pagination { |
16 | position:absolute; |
17 | left:0.7ex; /* relative to div#container */ |
18 | top:2.364ex; |
19 | width:88px; |
20 | height:12px; |
21 | text-align:left; |
22 | font-size:76%; |
23 | } |
24 | |
25 | .yui-skin-sam .yui-carousel .yui-carousel-nav ul { |
26 | /* Since we're taking up space with the paging text, adjust the position of the page nav for IE6/7 */ |
27 | *margin-left:-140px; |
28 | } |
view plain | print | ? |
After Carousel instantiation, we use the public registerPagination
method to register a text and/or HTML
template containing any one of the following Carousel tokens: numVisible
, numPages
,
numItems
, selectedItem
, currentPage
, firstVisible
, and/or
lastVisible
. Carousel's public updatePagination
is then called automatically and substitutes each
token with its respective data. The method continues to be called every time Carousel's state changes.
1 | YAHOO.util.Event.onDOMReady(function (ev) { |
2 | carousel = new YAHOO.widget.Carousel("container", { |
3 | // turn on multi-row to use in this example by passing an array of rows and cols |
4 | numVisible: [3, 2] |
5 | }); |
6 | |
7 | // register our text and/or HTML pagination template with embedded Carousel {tokens} |
8 | carousel.registerPagination("<strong>Image</strong> {firstVisible} - {lastVisible} <strong>of</strong> {numItems}"); |
9 | |
10 | carousel.render(); // get ready for rendering the widget |
11 | carousel.show(); // display the widget |
12 | }); |
view plain | print | ? |
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.
Note: Logging and debugging is currently turned off for this example.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings