YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: Button Control: Glowing Button

# Button Control: Glowing Button

This example demonstrates how to skin a Button instance to create a glossy, glass-like effect with a glowing background reminiscent of Aqua buttons found in Mac OS X.

View example in new window.

Skinning the Button widget is done using CSS. The stylesheet used for other Button examples is a minified version of the button-core.css and button-skin.css files. When customizing the Button skin, use the raw source files as a reference.

The button-core.css file includes foundational styling that clears the default padding, margins and borders for the `<button>` element as wells as normalizes its display type, whereas the button-skin.css file is used to apply colors, background images, etc. Skinning can be accomplished by either overriding the styles defined in the button-skin.css file, or by creating an entirely new skin file. When overriding styles, place them in a separate file to simplify integrating with YUI updates. The follow example illustrates how to create a new style for a Button instance from scratch.

Begin by creating a new Button instance.

var oButton = new YAHOO.widget.Button({ id: "ok-button", label: "OK", container: "buttoncontainer" });

Next, add style definitions for borders, background colors, and apply a transparent background to the Button's root element.

.yui-button { border-width: 1px 0; border-style: solid; border-color: #004d89; margin: auto .25em; /* Give the Button instance a transparent background image that provides a glossy, glass-like look. Since the background image is transparent, it can apply the glass effect the Button instance regardless of its background color. */ background: url(../button/assets/gloss.png) repeat-x left center; } .ie6 { /* Make background image transparent IE 6 using the AlphaImageLoader. */ background-image: none; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../button/assets/gloss.png', sizingMethod = 'scale'); } .yui-button .first-child { border-width: 0 1px; border-style: solid; border-color: #004d89; margin: 0 -1px; /* Using negative margins for rounded corners won't work in IE 6 and IE 7 (Quirks Mode Only), so set the "margin" property to "0" for those browsers. */ _margin: 0; } .yui-button button, .yui-button a { padding: 0 10px; font-size: 93%; /* 12px */ line-height: 2; /* ~24px */ *line-height: 1.7; /* For IE */ min-height: 2em; /* For Gecko */ *min-height: auto; /* For IE */ color: #fff; border: solid 1px #599acd; } .yui-button#ok-button { background-color: #004d89; }

Lastly, utilize the ColorAnim utility to animate the Button instance's background color.

/* Begin animating the Button instance's background color once it is appended to its containing element. */ oButton.on("appendTo", function () { /* Apply a special CSS class to be able to target IE 6 specifically in the CSS. */ if (YAHOO.env.ua.ie == 6) { oButton.addClass("ie6"); } // Create a new ColorAnim instance var oButtonAnim = new YAHOO.util.ColorAnim("ok-button", { backgroundColor: { to: "#b1ddff" } }); /* Restart the color animation each time the target color has been applied. */ oButtonAnim.onComplete.subscribe(function () { this.attributes.backgroundColor.to = (this.attributes.backgroundColor.to == "#b1ddff") ? "#016bbd" : "#b1ddff"; this.animate(); }); oButtonAnim.animate(); });

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

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

Reload with logging
and debugging disabled.

### Button Control Examples:

### More Button Control Resources:

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

Copyright © 2010 Yahoo! Inc. All rights reserved.

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