YUI 3.x Home -

YUI Library Examples: Dial: Basic Dial

Dial: Basic Dial

This example shows how to create a Dial widget from existing HTML on the page.

Drag the handle to set the value. When the handle has the focus, the following keys update its value: arrow keys, page up/down, home, and end. The action of these keys can be controlled via Dial's configuration attributes.

Creating a Dial

A Dial can be created easily and rendered into existing markup.

The Markup

The only markup requirement is an HTML element to contain the Dial.

  1. <div id="demo"></div>
<div id="demo"></div>

The JavaScript

Dial extends the Widget class, following the same pattern as any widget constructor. As a result, it accepts a configuration object to set the initial configuration for the widget.

After creating and configuring the new Dial, call the render method on the Dial object, passing it the selector for a container element. This renders it into the container and makes it usable.

Some commonly used configuration attributes are shown below.

  1. YUI({ filter: 'raw' }).use("dial", function(Y) {
  2.  
  3. var dial = new Y.Dial({
  4. min:-220,
  5. max:220,
  6. stepsPerRev:100,
  7. value: 30
  8. });
  9. dial.render("#demo");
  10.  
  11. });
YUI({ filter: 'raw' }).use("dial", function(Y) {
 
	var dial = new Y.Dial({
		min:-220,
		max:220,
		stepsPerRev:100,
		value: 30
	});
	dial.render("#demo");
 
});

Copyright © 2011 Yahoo! Inc. All rights reserved.

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