<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Keep The Web Weird - Interface Musings from Buck Wilson &#187; screencast</title>
	<atom:link href="http://www.keepthewebweird.com/category/screencast/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.keepthewebweird.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 10 Dec 2008 04:54:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a Nice Slider With jQuery UI</title>
		<link>http://www.keepthewebweird.com/creating-a-nice-slider-with-jquery-ui/</link>
		<comments>http://www.keepthewebweird.com/creating-a-nice-slider-with-jquery-ui/#comments</comments>
		<pubDate>Sun, 30 Mar 2008 00:08:06 +0000</pubDate>
		<dc:creator>Buck</dc:creator>
				<category><![CDATA[interface]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[screencast]]></category>

		<guid isPermaLink="false">http://www.keepthewebweird.com/?p=27</guid>
		<description><![CDATA[Sliders have many things going for them as a UI element; they offer the benefit restricting the choice a user has, without taking up the space of a drop down. If you need to ask the user to select a number between a range, you can either do an input box with validation, a drop [...]]]></description>
			<content:encoded><![CDATA[<p>Sliders have many things going for them as a UI element; they offer the benefit restricting the choice a user has, without taking up the space of a drop down. If you need to ask the user to select a number between a range, you can either do an input box with validation, a drop down select element listing each possibility, or you can do a slider. </p>
<p>One drawback of a slider is the user not knowing what he&#8217;s selected as there&#8217;s no discrete output. If you are sliding to scale something, you can eyeball something, but wouldn&#8217;t it be nice if the slider provided some feedback to the user (&#8221;50%&#8221;) as the user was fiddling with it? I&#8217;m going to show you how to do just that with the jQuery UI library. </p>
<div class="update">
Sorry kids, the movie has been deleted somehow as a result of the latest Wordpress update. I&#8217;m working with Mediatemple to see a) what on earth happened with their install script to delete everything that&#8217;s NOT Wordpress and b) if they can recover anything.</p>
<p>I had a local backup of the demo, thank goodness, so that&#8217;s still up. Unfortunately, not the video.
</p></div>
<div class="download">
<a href='http://www.keepthewebweird.com/demo/slider/tutorial.mov'>Download the Screencast <br/><span>creating a jQuery Slider</span></a>
</div>
<p><a href='http://www.keepthewebweird.com/demo/slider'>Check out the demo here</a></p>
<p>The necessary dependencies :</p>
<ul>
<li><a href="http://ui.jquery.com">jQuery Slider &amp; UI Base</a></li>
<li><a href="http://www.jquery.com">jQuery</a></li>
</ul>
<p>The code I used is as follows : </p>
<h3>HTML</h3>
<pre><code class="html">&lt;div id=&apos;container&apos;&gt;
	&lt;div class=&quot;slider_container&quot;&gt;
		&lt;div class=&apos;small_label&apos;&gt;&lt;/div&gt;
		&lt;div class=&apos;slider_bar&apos;&gt;
			&lt;div id=&quot;slider_callout&quot;&gt;&lt;/div&gt;
			&lt;div id=&apos;slider1_handle&apos; class=&apos;slider_handle&apos;&gt;&lt;/div&gt;
		&lt;/div&gt;
		&lt;div class=&apos;large_label&apos;&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h3>CSS</h3>
<pre><code class="css">body { background: #284a6e; }
#container { height: 100px; border: 1px solid #284a6e;}
.slider_container { position: relative; margin-top: 50px; height: 40px;}
.small_label { background: url(minus.gif) no-repeat; height: 19px; width: 19px; overflow: hidden; float: left; }
.slider_bar { background: url(bar.gif) no-repeat; height: 19px; width: 260px;  float: left; margin: 0px 5px; position: relative;}
.large_label { background: url(plus.gif) no-repeat; height: 19px; width: 19px; overflow: hidden; float: left; }
.slider_handle { background: url(selector.png) no-repeat; height: 19px; width: 20px; overflow: hidden; position: absolute; top: 1px;}
#slider_callout { background: url(callout.gif) no-repeat; height: 45px; width: 38px; overflow: hidden; position: absolute; top: -50px; margin-left:-10px;  padding: 8px 0px 0px 0px; font-family: "Myriad Pro"; color: #284a6e; font-weight: bold; text-align: center;}
</code></pre>
<p><b>Update:</b> A couple commenters noticed a little outline gremlin in Firefox 3 when using the slider. Just add <code class="css">* :focus { outline:none } </code> to get rid of it. I&#8217;m not sure which element the outline is on, so applying it to * can&#8217;t hurt <img src='http://www.keepthewebweird.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h3>JavaScript</h3>
<p>After I recorded the video, it dawned on me that there&#8217;s a way to do this that is a bit simpler: by using the ui object passed in by slider, and grabbing the &#8220;left&#8221; css property of the handle. That way, the callout matches the css handle at all times, with no calculations needed; and you can reserve minValue and maxValue to return values that are useful for your web application. </p>
<p class='update'>Thanks to Andrew and John in the comments, I have fixed some bugs with the code. Now you can click on the bar itself and the callout will fire correctly. For this I utilized the &#8220;stop&#8221; event, checked if the callout was already visible, and displayed it if not. </p>
<p>The code looks like this : </p>
<pre><code class="javascript">
$(function() {
	$('#slider_callout').hide();
	var calloutVisible = false;
	$('.slider_bar').slider({
		handle: '.slider_handle',
		minValue: 0,

		maxValue: 25,
		start: function(e, ui) {
			$('#slider_callout').fadeIn('fast', function() { calloutVisible = true;});
		},
		stop: function(e, ui) {
			if (calloutVisible == false) {
				$('#slider_callout').fadeIn('fast', function() { calloutVisible = true;});
				$('#slider_callout').css('left', ui.handle.css('left')).text(Math.round(ui.value));
			}
			$('#slider_callout').fadeOut('fast', function() { calloutVisible = false; });
		},
		slide: function(e, ui) {
			$('#slider_callout').css('left', ui.handle.css('left')).text(Math.round(ui.value));
		}
	});
});
</code></pre>
<p>For reference purposes, here is the code I used in the video : </p>
<pre><code class="javascript">
$(function() {
	$('#slider_callout').hide();
	$('.slider_bar').slider({
		handle: '.slider_handle',
		minValue: 0,
		maxValue: 240,
		start: function(e, ui) {
			$('#slider_callout').fadeIn('fast');
		},
		stop: function(e, ui) {
			$('#slider_callout').fadeOut('fast');
		},
		slide: function(e, ui) {
			$('#slider_callout').css('left', ui.value).text(Math.round(ui.value * (100/240)));
		}
	});
});
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.keepthewebweird.com/creating-a-nice-slider-with-jquery-ui/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
<enclosure url="http://www.keepthewebweird.com/demo/slider/tutorial.mov" length="87907380" type="video/quicktime" />
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.781 seconds -->

<!-- Page not cached by WP Super Cache. Could not get mutex lock. -->
