<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example: Image Sprite Animation with Dial</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<h1>Example: Image Sprite Animation with Dial</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<p>This example shows how to use a <code>Dial</code> widget to animate an image sprite.</p>
<p>Drag the <code>Dial</code> handle, or use the keyboard arrow keys to see the duck image "animate".</p>
</div>
<div class="example yui3-skin-sam">
<style>
.example {
background-color: #59554F;
text-align: center;
}
.example .container {
text-align: left;
position: relative;
width: 554px;
margin: 10px auto;
padding: 0;
font-family: georgia;
}
.example #demo {
position: absolute;
top: -10px;
left: 350px;
}
.example #duck {
width:300px;
height:188px;
background:url(../assets/dial/images/sprite_duck.jpg) no-repeat;
background-position: 0 0;
border:solid 1px #958A71;
-moz-box-shadow:7px 7px 10px rgba(0,0,0,0.3);
-webkit-box-shadow:7px 7px 10px rgba(0,0,0,0.3);
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
.example .yui3-dial-label {
visibility:hidden;
}
.example .yui3-dial-north-mark {
visibility:hidden;
}
.example .yui3-skin-sam #demo .yui3-dial-ring {
-moz-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3);
}
.example #text {
color:#C5B291;
}
.example #text h2 {
font-size:261%;
color:#EEE5D6;
text-shadow: 2px 2px 7px #000;
margin: 0;
font-family: georgia;
}
.example #text h3 {
color:#EEE5D6;
font-size: 100%;
margin: 0.6em 0;
font-family: georgia;
}
.example #text p {
margin: 0.5em 0;
font-size:135%;
line-height: 1.2em;
}
</style>
<div class="container">
<div id="duck"></div>
<div id="demo"></div>
<div id="text">
<h3>Lot #562</h3>
<h2>Duck Decoy - Thomas Jefferson</h2>
<p>
Hand carved and signed by Thomas Jefferson.
circa 1785. Native hardwoods, stains, pigments.
Glass bead eyes.
</p>
<p>
Opening bid $93,000
</p>
</div>
</div>
<script type="text/javascript">
YUI().use("dial", function(Y) {
var oneFrameWidth = 300,
framesInSprite = 13;
var dial = new Y.Dial({
min: 0,
max: 26000,
value: 13000, // initial value in the middle of a large range allows rotation both ways
minorStep: 1,
majorStep: 2,
stepsPerRevolution: framesInSprite,
diameter: 150
});
dial.render('#demo');
// Reposition the duck sprite background image
dial.on( "valueChange", function(e){
// Handle values greater than one revolution
var moduloValue = (e.newVal % framesInSprite);
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px');
}, '#duck' );
});
</script>
</div>
<h3>The Image Sprite</h3>
<p><img src="../assets/dial/images/sprite_duck.jpg" width="676" height="33"/></p>
<h3>The Markup</h3>
<p>The <code><div id="duck"></div></code> element will have the sprite as its background-image.
<p>The <code><div id="demo"></div></code> element will contain the dial.</p>
<p></p>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code><body></code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre>
<pre class="code prettyprint"><div class="container">
<div id="duck"></div>
<div id="demo"></div>
<div id="text">
<h3>Lot #562</h3>
<h2>Duck Decoy - Thomas Jefferson</h2>
<p>
Hand carved and signed by Thomas Jefferson.
circa 1785. Native hardwoods, stains, pigments.
Glass bead eyes.
</p>
<p>
Opening bid $93,000
</p>
</div>
</div></pre>
<h3>The JavaScript</h3>
<p>The <code>stepsPerRevolution</code> attribute of the <code>Dial</code>
is given a value equal to the number of frames in the sprite.
</p>
<p>
On <code>valueChange</code> of the <code>dial</code>, the <code>background-position</code> of <code><div id="duck"></code>
is changed to a new multiple of the
width of one frame in the sprite.
</p>
<pre class="code prettyprint"><script type="text/javascript">
YUI().use("dial", function(Y) {
var oneFrameWidth = 300,
framesInSprite = 13;
var dial = new Y.Dial({
min: 0,
max: 26000,
value: 13000, // initial value in the middle of a large range allows rotation both ways
minorStep: 1,
majorStep: 2,
stepsPerRevolution: framesInSprite,
diameter: 150
});
dial.render('#demo');
// Reposition the duck sprite background image
dial.on( "valueChange", function(e){
// Handle values greater than one revolution
var moduloValue = (e.newVal % framesInSprite);
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px');
}, '#duck' );
});
</script></pre>
<h3>Complete Example Source</h3>
<pre class="code prettyprint"><style>
.example {
background-color: #59554F;
text-align: center;
}
.example .container {
text-align: left;
position: relative;
width: 554px;
margin: 10px auto;
padding: 0;
font-family: georgia;
}
.example #demo {
position: absolute;
top: -10px;
left: 350px;
}
.example #duck {
width:300px;
height:188px;
background:url(../assets/dial/images/sprite_duck.jpg) no-repeat;
background-position: 0 0;
border:solid 1px #958A71;
-moz-box-shadow:7px 7px 10px rgba(0,0,0,0.3);
-webkit-box-shadow:7px 7px 10px rgba(0,0,0,0.3);
-moz-border-radius:3px;
-webkit-border-radius:3px;
}
.example .yui3-dial-label {
visibility:hidden;
}
.example .yui3-dial-north-mark {
visibility:hidden;
}
.example .yui3-skin-sam #demo .yui3-dial-ring {
-moz-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 5px 5px 6px rgba(0, 0, 0, 0.3);
}
.example #text {
color:#C5B291;
}
.example #text h2 {
font-size:261%;
color:#EEE5D6;
text-shadow: 2px 2px 7px #000;
margin: 0;
font-family: georgia;
}
.example #text h3 {
color:#EEE5D6;
font-size: 100%;
margin: 0.6em 0;
font-family: georgia;
}
.example #text p {
margin: 0.5em 0;
font-size:135%;
line-height: 1.2em;
}
</style>
<div class="container">
<div id="duck"></div>
<div id="demo"></div>
<div id="text">
<h3>Lot #562</h3>
<h2>Duck Decoy - Thomas Jefferson</h2>
<p>
Hand carved and signed by Thomas Jefferson.
circa 1785. Native hardwoods, stains, pigments.
Glass bead eyes.
</p>
<p>
Opening bid $93,000
</p>
</div>
</div>
<script type="text/javascript">
YUI().use("dial", function(Y) {
var oneFrameWidth = 300,
framesInSprite = 13;
var dial = new Y.Dial({
min: 0,
max: 26000,
value: 13000, // initial value in the middle of a large range allows rotation both ways
minorStep: 1,
majorStep: 2,
stepsPerRevolution: framesInSprite,
diameter: 150
});
dial.render('#demo');
// Reposition the duck sprite background image
dial.on( "valueChange", function(e){
// Handle values greater than one revolution
var moduloValue = (e.newVal % framesInSprite);
Y.one('#duck').setStyle('backgroundPosition', (moduloValue * -oneFrameWidth) + 'px 0px');
}, '#duck' );
});
</script></pre>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Create a Dial from existing markup on the page - a simple use case.">
<a href="dial-basic.html">Basic Dial</a>
</li>
<li data-description="Link a Dial with a text input field.">
<a href="dial-text-input.html">Dial Linked With Text Input</a>
</li>
<li data-description="Use image backgrounds to control the visual display of a Dial.">
<a href="dial-image-background.html">Dial With Image Background</a>
</li>
<li data-description="Use images to surround a Dial instance and provide additional styling.">
<a href="dial-image-surrounding.html">Dial With a Surrounding Image</a>
</li>
<li data-description="This example employs Dial to drive an interactive UI.">
<a href="dial-interactive.html">Dial With Interactive UI</a>
</li>
<li data-description="This example shows how to use Dial to animate an image sprite.">
<a href="duck.html">Image Sprite Animation with Dial</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples That Use This Component</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Use the HSL color picker to select a new color. Then chose the color type you like best.">
<a href="../color/hsl-picker.html">HSL Color Picker</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/dial',
name: 'duck',
title: 'Image Sprite Animation with Dial',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('dial-basic');
YUI.Env.Tests.examples.push('dial-text-input');
YUI.Env.Tests.examples.push('dial-image-background');
YUI.Env.Tests.examples.push('dial-image-surrounding');
YUI.Env.Tests.examples.push('dial-interactive');
YUI.Env.Tests.examples.push('duck');
YUI.Env.Tests.examples.push('hsl-picker');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>