<?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>CSSKarma &#187; jquery</title> <atom:link href="http://www.csskarma.com/blog/tag/jquery/feed/" rel="self" type="application/rss+xml" /><link>http://www.csskarma.com/blog</link> <description>display your style</description> <lastBuildDate>Tue, 31 Jan 2012 15:18:44 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>HTML 5 Form Validation with Yepnope Fallback</title><link>http://www.csskarma.com/blog/form-validate-yepnope-fallback/</link> <comments>http://www.csskarma.com/blog/form-validate-yepnope-fallback/#comments</comments> <pubDate>Thu, 04 Aug 2011 13:39:03 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[forms]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[performance]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=940</guid> <description><![CDATA[In my last post about creating a proper fallback when using the new HTML 5 form validation I mentioned using modernizr to detect for support, then creating an if statement to call the jQuery validate plugin. One of the commentors mentioned using yepnope for this instead of loading the jQuery validation plugin by default. Since [...]]]></description> <content:encoded><![CDATA[<p>In my <a
href="http://www.csskarma.com/blog/required-input-fallback/" title="Required input fields with JS fallback">last post</a> about creating a proper fallback when using the new HTML 5 form validation I mentioned using modernizr to detect for support, then creating an if statement to call the jQuery validate plugin.</p><p>One of the commentors mentioned using yepnope for this instead of loading the jQuery validation plugin by default. Since modernizr has yepnope now anyway, I thought it was a good idea. And here we are with some ne code to look at.</p><p><a
href="http://www.csskarma.com/lab/_javascript/no_require/">View the demo</a></p><h3>Dependencies</h3><ul><li><a
href="http://www.jquery.com">jQuery</a></li><li><a
href="http://www.modernizr.com/">Modernizr (with yepnope)</a></li><li><a
href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery Validate plugin</a></li></ul><h3>The HTML</h3><pre><code>&lt;form action="" method="post"&gt;

    &lt;ul&gt;
        &lt;li&gt;
            &lt;label for="name"&gt;Name&lt;/label&gt;
            &lt;input type="text" name="name" id="name" required&gt;
        &lt;/li&gt;
        
        &lt;li&gt;
            &lt;label for="email"&gt;Email&lt;/label&gt;
            &lt;input type="email" name="email" id="email" required&gt;
        &lt;/li&gt;
    
        &lt;li&gt;
            &lt;button type="submit"&gt;Submit&lt;/button&gt;
        &lt;/li&gt;
    &lt;/ul&gt;
    
&lt;/form&gt;</code></pre><h3>The JS</h3><pre><code>(function ($) {

	<span>// set and cache some variables, change var forms to whatever forms you want to validate</span>
	var forms = $('form'),
		formsCount = forms.length,
		items = forms.find('input[required]'),
		count = items.length;

	<span>// check for "required" input support with modernizr</span>
	if (Modernizr.input.required) {

		<span>// do something else, maybe customize the output messages?</span>

	} else {

		<span>// loop though each required input and set the required and type class jQuery validate needs</span>
		for (var i = 0; i < count; i += 1) {
			var obj = items[i];
			$(obj).attr('class', 'required ' + obj.getAttribute('type')).removeAttr('required');
		};

		<span>// after the classes are set, load in the plugin with yepnope , you can do this with Modernizr.load as well</span>
		yepnope([{
			load: 'js/validate.js',
			complete: function () {

				<span>// after the plugin is loaded, call the method on each form listed at the top</span>
				for (var i = 0; i < formsCount; i += 1) {
					$(forms[i]).validate();
				}
			}
		}]);

	} <span>// if required supported</span>

}(jQuery));
</code></pre><p>I&#8217;m not really a fan of script loaders, especially when using them to load a core script file, like jQuery, but I think this is actually a pretty good use of yepnope.</p><p>I don&#8217;t know about you folk(s), but I&#8217;ll be using this moving forward. Any comments/corrections are obviously welcome.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/form-validate-yepnope-fallback/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Quick Tip on Global Scope and jQuery</title><link>http://www.csskarma.com/blog/global-scope-jquery/</link> <comments>http://www.csskarma.com/blog/global-scope-jquery/#comments</comments> <pubDate>Fri, 08 Apr 2011 12:34:29 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Design]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=890</guid> <description><![CDATA[Before launch of a new site, I always take the time to run my JavaScript through a checker. Personally, I use JS Lint. It&#8217;s not the prettiest thing, but it works great to pick up small errors and elements of bad practice. You&#8217;ll get alerts like &#8220;unused variable&#8221;, &#8220;don&#8217;t use eval(), it&#8217;s evil&#8221;, &#8220;implied global&#8221;. [...]]]></description> <content:encoded><![CDATA[<p>Before launch of a new site, I always take the time to run my JavaScript through a checker. Personally, I use <a
href="http://jslint.com/">JS Lint</a>. It&#8217;s not the prettiest thing, but it works great to pick up small errors and elements of bad practice. You&#8217;ll get alerts like &#8220;unused variable&#8221;, &#8220;don&#8217;t use eval(), it&#8217;s evil&#8221;, &#8220;implied global&#8221;.</p><p>I find that it&#8217;s best not to argue with JS Lint, just fix the problem.</p><p>One that I had encountered quite a bit while running jQuery through JS Lint was &#8220;Implied global: $&#8221;.</p><p>Up until a week or two ago, I was just blowing it off, because, I mean, come on, it&#8217;s a $, it kind of is global when using jQuery. For whatever reason I had a quick talk with <a
href="http://twitter.com/akira_x">@akira_x</a> and we figured out what was going on and how to fix it.</p><p>The solution is actually similar to how we build jQuery plugins, but without the real plugin model, just normal site code.</p><h3>Evolution of the the document.ready</h3><p>When jQuery first came out, this is how we would used document.ready as a wrapper for custom jQuery:</p><pre><code>$(document).ready(function() {
// jquery code here
 });</code></pre><p>Then we moved on to the short cut method:</p><pre><code>$(function(){
// jquery code here
});</code></pre><p>Both of these methods are technically fine, but they both leave &#8220;$&#8221; as an implied global. This may not be an issue for most of us since we only use jQuery, so who really cares is $ is global, right?</p><p>We can, however make sure (just in case, because we&#8217;re all good coders) that there are no future library or JavaScript collisions by containing the scope of $ with:</p><pre><code>(function($) {
	// jquery here
}(jQuery));</code></pre><p>This will still cause JS Lint to throw an &#8220;implied global&#8221; alert, but it will be for &#8220;jQuery&#8221; rather than &#8220;$&#8221;. Personally, I feel like it&#8217;s better.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/global-scope-jquery/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Sliding Labels Official Plugin Release [ver. 3.2]</title><link>http://www.csskarma.com/blog/sliding-labels-plugin/</link> <comments>http://www.csskarma.com/blog/sliding-labels-plugin/#comments</comments> <pubDate>Tue, 29 Jun 2010 12:27:23 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[form]]></category> <category><![CDATA[javascipt]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[ui]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=805</guid> <description><![CDATA[View Demo Plugin Minified Plugin Version: 3.2 – Added a &#8220;className&#8221; option so you don&#8217;t have to use &#8220;.slider&#8221; as the wrapper Version 3.1: Changed &#8220;children&#8221; to &#8220;find&#8221; so it will work with a UL. Thanks to Oro for the feedback Version 3 of Sliding Labels brought some big changes, the largest being that I [...]]]></description> <content:encoded><![CDATA[<div
id="slidinglabels-plugin-release"><ul
class="demo"><li><a
href="http://www.csskarma.com/lab/plugin_slidinglabels/">View Demo</a></li><li><a
href="http://www.csskarma.com/lab/jquery.plugins/jquery.slidinglabels.js">Plugin</a></li><li><a
href="http://www.csskarma.com/lab/jquery.plugins/jquery.slidinglabels.min.js">Minified Plugin</a></li></ul><p><strong>Version: 3.2 – Added a &#8220;className&#8221; option so you don&#8217;t have to use &#8220;.slider&#8221; as the wrapper</strong></p><p>Version 3.1: Changed &#8220;children&#8221; to &#8220;find&#8221; so it will work with a UL. Thanks to <a
href="http://www.csskarma.com/blog/sliding-labels-plugin/comment-page-1/#comment-85490">Oro</a> for the feedback</p><p>Version 3 of Sliding Labels brought some big changes, the largest being that I finally converted it into a working jQuery plugin.</p><p>Maybe it was the 200 e-mails requesting an official plugin, maybe it was my curiosity. Whatever it was, I heard everyone and I wanted to let you know that I&#8217;m listening to all the feature requests and bug reports; and I really do appreciate them.</p><h3>Additions to version 3</h3><p><strong>Plugin status</strong>: Obviously creating an official plugin was the biggest change</p><p><strong>Position: relative</strong>: It seemed like a lot of the questions I was getting had to do with adding <code>position:relative</code> to the .slider element in the CSS, so I just moved that into the script.</p><p><strong>Animation speed</strong>: I added an option to easily control the animation speed. It can take strings like &#8220;fast&#8221; and &#8220;slow&#8221; or any numeric value.</p><p><strong>Axis option</strong>: I got a lot of requests to add in some functionality to have the label slide up rather than only to the left. I added this in with an &#8220;axis&#8221; variable which can take either &#8220;x&#8221; or &#8220;y&#8221; for sliding direction</p><h3>Subtractions to version 3</h3><p><strong>Label Color</strong>: Originally I had this in the script so it looked nicer inline to the field, but I got to thinking that this really should be defined in the CSS, and it&#8217;s just color; so I took it out.</p><h3>Using the plugin</h3><p>Just like the previous version, you need an element wrapping the <code>&lt;label&gt;</code> and <code>&lt;input&gt;</code> elements. I use a <code>&lt;div&gt;</code> in the demo, but you can use whatever you&#8217;d like. The only requirement is that it have the class name &#8220;slider&#8221;. I can change that if anyone finds it to be annoying, but <strong>let me know and I&#8217;ll update the script</strong></p><h4>HTML</h4><pre><code>
&lt;div class="form-slider"&gt;
&lt;label for="user"&gt;User name&lt;/label&gt;
&lt;input type="text" id="user" name="user"&gt;
&lt;/div&gt;</code></pre><h4>JavaScript</h4><pre><code>
$(function(){ $('#contactform').slidinglabels({
/* these are all optional */
className : 'form-slider', // the class you're wrapping the label &amp; input with -&gt; default = slider
topPosition : '5px', // how far down you want each label to start
leftPosition : '5px', // how far left you want each label to start
axis : 'x', // can take 'x' or 'y' for slide direction
speed : 'fast' // can take 'fast', 'slow', or a numeric value
});
});</code></pre><p>That&#8217;s all there is to it. Let me know what you think, any extra features you&#8217;d like and any bugs. I should be submitting this to <a
href="http://jquery.com">jQuery.com</a> in the next few days.</p></div> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/sliding-labels-plugin/feed/</wfw:commentRss> <slash:comments>61</slash:comments> </item> <item><title>Sliding Labels v2 &#8211; Patch</title><link>http://www.csskarma.com/blog/sliding-labels-v2/</link> <comments>http://www.csskarma.com/blog/sliding-labels-v2/#comments</comments> <pubDate>Tue, 02 Feb 2010 15:51:37 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Design]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[forms]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[ui]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=772</guid> <description><![CDATA[Please use version 3 of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ Last week I wrote an article about sliding form labels that got quite a bit of attention. Many of the commenters brought up a couple good points/bug in the Sliding Label code that I wanted to address and provide a [...]]]></description> <content:encoded><![CDATA[<div
style="background: #fffcdB; padding: 10px; margin: 0 0 30px; border: 1px solid #bebf6b; clear: both; font-size: 16px;">Please use <strong>version 3</strong> of sliding labels with updated options and bug fixes at: <a
href="http://www.csskarma.com/blog/sliding-labels-plugin/">http://www.csskarma.com/blog/sliding-labels-plugin/</a></div><p>Last week I wrote an article about sliding form labels that got quite a bit of attention. Many of the commenters brought up a couple good points/bug in the Sliding Label code that I wanted to address and provide a patch for:</p><ul><li>The sliding label was barfing out in <strong>Safari</strong> when auto-fill was active</li><li>The default scripting didn&#8217;t work on <strong>textareas</strong></li></ul><p>I sat down yesterday and wrote a patch/new version of sliding labels which I think addresses these two problems.</p><p
class="demo"><a
href="http://www.csskarma.com/lab/plugin_slidinglabels/">View the Demo</a></p><h3>The new jQuery</h3><pre><code>$(function(){
$('form#info .slider label').each(function(){
	var labelColor = '#999';
	var restingPosition = '5px';

	<span>// style the label with JS for progressive enhancement</span>
	$(this).css({
		'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    		        'z-index' : '99'
	});

	var inputval = $(this).next().val();

	<span>// grab the label width, then add 5 pixels to it</span>
	var labelwidth = $(this).width();
	var labelmove = labelwidth + 5 +'px';

	<span>// onload, check if a field is filled out, if so, move the label out of the way</span>
	if(inputval !== ''){
		$(this).stop().animate({ 'left':'-'+labelmove }, 1);
	}    	

	<span>// if the input is empty on focus move the label to the left
	// if it's empty on blur, move it back</span>
	$('input, textarea').focus(function(){
		var label = $(this).prev('label');
		var width = $(label).width();
		var adjust = width + 5 + 'px';
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':'-'+adjust }, 'fast');
		} else {
			label.css({ 'left':'-'+adjust });
		}
	}).blur(function(){
		var label = $(this).prev('label');
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':restingPosition }, 'fast');
		}	

	});
}); <span>// End "each" statement</span>
}); <span>// End loaded jQuery</span></code></pre><h3>Textarea HTML</h3><p>The HTML for the textarea follows the same convention as the rest of the inputs, in only needing a wrapping element.</p><pre><code>&lt;div id="comment-wrap"  class="slider"&gt;
    &lt;label for="comment"&gt;Comment&lt;/label&gt;
    &lt;textarea cols="53" rows="10" id="comment"&gt;&lt;/textarea&gt;
&lt;/div&gt;&lt;!--/#comment-wrap--&gt;</code></pre><p>There are no major changes to the plugin, just a few tweaks. If you find anymore bug, please let me know.</p><p
class="demo"><a
href="http://www.csskarma.com/lab/plugin_slidinglabels/">View the Demo</a></p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/sliding-labels-v2/feed/</wfw:commentRss> <slash:comments>116</slash:comments> </item> <item><title>Form Design with Sliding Labels</title><link>http://www.csskarma.com/blog/sliding-labels/</link> <comments>http://www.csskarma.com/blog/sliding-labels/#comments</comments> <pubDate>Tue, 19 Jan 2010 19:01:56 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Design]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[forms]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[ui]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=689</guid> <description><![CDATA[Please use the latest version of sliding labels with updated options and bug fixes at: http://www.csskarma.com/blog/sliding-labels-plugin/ A few weeks ago I was reading an article on form UI by Luke Wroblewski of Yahoo!. For those who aren&#8217;t familiar with Luke, he (quite literally) wrote the book on good form design. In the article, one certain [...]]]></description> <content:encoded><![CDATA[<div
style="background: #fffcdB; padding: 10px; margin: 0 0 30px; border: 1px solid #bebf6b; clear: both; font-size: 16px;">Please use <strong>the latest version</strong> of sliding labels with updated options and bug fixes at: <a
href="http://www.csskarma.com/blog/sliding-labels-plugin/">http://www.csskarma.com/blog/sliding-labels-plugin/</a></div><p>A few weeks ago I was reading an <a
href="http://www.lukew.com/ff/entry.asp?968">article</a> on form UI by <a
href="http://www.lukew.com/">Luke Wroblewski</a> of <a
href="http://www.yahoo.com/">Yahoo!</a>. For those who aren&#8217;t familiar with Luke, he (<a
href="http://rosenfeldmedia.com/books/webforms/">quite literally</a>) wrote the book on good form design.</p><p>In the article, one certain section about placing labels inside of form fields stood out to me:</p><blockquote
cite="http://www.lukew.com/ff/entry.asp?968"><p>Because labels within fields need to go away when people are entering their answer into an input field, the context for the answer is gone. So if you suddenly forget what question you’re answering, tough luck—the label is nowhere to be found. As such, labels within inputs aren’t a good solution for long or even medium-length forms. When you’re done filling in the form, all the labels are gone! That makes it a bit hard to go back and check your answers.<cite>Luke Wroblewski</cite></p></blockquote><p>He brings up a good point. Generally speaking, you can look at a field that says &#8220;Tim Wright&#8221; and know that it was a field for your (my) name. But for long forms, yea, I do agree that you can forget some of the questions you answered.</p><p>For best practice, Luke talks about leaving your labels outside the form field so it&#8217;s always available to the user. I do think it&#8217;s a pretty good solution, but <strong>I think we can get a little more creative than that</strong>.</p><h3>Enter: Sliding Labels</h3><p>After reading that article it occurred to me that there&#8217;s no reason we can&#8217;t have the best of both worlds. I like how inline labels look, and I see Luke&#8217;s point about them disappearing as you fill out the form. But, we have jQuery, we know about progressive enhancement, and we have creative minds, so let&#8217;s build something that allows us to keep the label inline, but <strong>slide it off to the left</strong> (or up, whichever you prefer) rather than going away on click.</p><p
class="demo"><a
href="http://www.csskarma.com/lab/plugin_slidinglabels/">View demo</a></p><h4>The HTML</h4><pre><code>&lt;form action="" method="post" id="info"&gt; &lt;h2&gt;Contact Information&lt;/h2&gt; &lt;div id="name-wrap" class="slider"&gt; &lt;label for="name"&gt;Name&lt;/label&gt; &lt;input type="text" id="name" name="name"&gt; &lt;/div&gt;<span>&lt;!--/#name-wrap--&gt;</span> &lt;div id="email-wrap" class="slider"&gt; &lt;label for="email"&gt;E&amp;ndash;mail&lt;/label&gt; &lt;input type="text" id="email" name="email"&gt; &lt;/div&gt;<span>&lt;!--/#email-wrap--&gt;</span> &lt;div id="street-wrap" class="slider"&gt; &lt;label for="st"&gt;Street&lt;/label&gt; &lt;input type="text" id="st" name="st"&gt; &lt;/div&gt;<span>&lt;!--/#street-wrap--&gt;</span> &lt;div id="city-wrap" class="slider"&gt; &lt;label for="city"&gt;City &amp;amp; State&lt;/label&gt; &lt;input type="text" id="city" name="city"&gt; &lt;/div&gt;<span>&lt;!--/#city-wrap--&gt;</span> &lt;div id="zip-wrap" class="slider"&gt; &lt;label for="zip"&gt;Zip code&lt;/label&gt; &lt;input type="text" id="zip" name="zip"&gt; &lt;/div&gt;<span>&lt;!--/#zip-wrap--&gt;</span> &lt;input type="submit" id="btn" name="btn" value="submit"&gt; &lt;/form&gt;</code></pre><p>The only necessary items to make sliding labels (as I built it) work are the wrapper element (<code>DIV</code> in my case) and applying a class of &#8220;slider&#8221; to it (you can change this easily in the JavaScript).</p><p>At this point we have a pretty basic, and ugly form</p><p><img
src="http://www.csskarma.com/blog/wp-content/uploads/slidinglabels_nocss.png" alt="slidinglabels no css" /></p><h4>The CSS</h4><pre><code>body { font:12px/1.3 Arial, Sans-serif; } form { width:380px;padding:0 90px 20px;margin:auto;background:#f7f7f7;border:1px solid #ddd; } div { clear:both;position:relative;margin:0 0 10px; } label { cursor:pointer;display:block; } input[type="text"] { width:300px;border:1px solid #999;padding:5px;-moz-border-radius:4px; } input[type="text"]:focus { border-color:#777; } input[name="zip"] { width:150px; } /* submit button */ input[type="submit"] { cursor:pointer;border:1px solid #999;padding:5px;-moz-border-radius:4px;background:#eee; } input[type="submit"]:hover, input[type="submit"]:focus { border-color:#333;background:#ddd; } input[type="submit"]:active{ margin-top:1px; } </code></pre><p>The only 100% necessary CSS in there is the <code>position:relative</code> on the wrapper element (<code>DIV</code>). The rest is basically cosmetic and you can mess with it as you see fit.</p><p>At this point you should have a pretty normal looking form with labels on top of their respective inputs.</p><p><img
src="http://www.csskarma.com/blog/wp-content/uploads/labelslider_nojs.png" alt="labelslider no js" /></p><h4>The jQuery</h4><p>Now for the section everyone skipped to, provided you didn&#8217;t go straight to the demo (which I usually do).</p><pre><code>$(function(){ $('form#info .slider label').each(function(){ var labelColor = '#999'; var restingPosition = '5px'; <span>// style the label with JS for progressive enhancement</span> $(this).css({ 'color' : labelColor, 'position' : 'absolute', 'top' : '6px', 'left' : restingPosition, 'display' : 'inline', 'z-index' : '99' }); <span>// grab the input value</span> var inputval = $(this).next('input').val(); <span>// grab the label width, then add 5 pixels to it</span> var labelwidth = $(this).width(); var labelmove = labelwidth + 5; <span>//onload, check if a field is filled out, if so, move the label out of the way</span> if(inputval !== ''){ $(this).stop().animate({ 'left':'-'+labelmove }, 1); } <span>// if the input is empty on focus move the label to the left</span> <span>// if it's empty on blur, move it back</span> $('input').focus(function(){ var label = $(this).prev('label'); var width = $(label).width(); var adjust = width + 5; var value = $(this).val(); if(value == ''){ label.stop().animate({ 'left':'-'+adjust }, 'fast'); } else { label.css({ 'left':'-'+adjust }); } }).blur(function(){ var label = $(this).prev('label'); var value = $(this).val(); if(value == ''){ label.stop().animate({ 'left':restingPosition }, 'fast'); } }); }) });</code></pre><p>At this point, you should have a fully working sliding label form!</p><p><img
src="http://www.csskarma.com/blog/wp-content/uploads/labelslider_final.png" alt="labelslider final" /></p><p
class="demo"><a
href="http://www.csskarma.com/lab/plugin_slidinglabels/">View demo</a></p><p>Making sure everything is still usable without JavaScript is important (no matter what people say), it&#8217;s just a basic principle of progressive enhancement. Believe it or not, there are still people browsing without JavaScript (blackberry users &#8211; turned off by default). So creating the interaction in layers, as we did, will help it be <strong>past-proof</strong>.</p><p>Try it out and let me know what you think. So far I&#8217;ve used it on a password change form, so definitely let me know if you find a place to use it!</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/sliding-labels/feed/</wfw:commentRss> <slash:comments>144</slash:comments> </item> <item><title>Conditional Animation Speed in jQuery</title><link>http://www.csskarma.com/blog/conditional-animation-speed/</link> <comments>http://www.csskarma.com/blog/conditional-animation-speed/#comments</comments> <pubDate>Fri, 08 Jan 2010 17:00:43 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Design]]></category> <category><![CDATA[advanced]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[ui]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=694</guid> <description><![CDATA[For years (and by &#8220;years&#8221;, I most likely mean &#8220;the years since I started using jQuery&#8230; maybe 2&#8243;), there&#8217;s been one aspect of jQuery that&#8217;s bugged the crap out of me, the animation speed. View demo We&#8217;ve all probably seen the problem that happens in many drop down menus of varying height. We set slideDown(300) [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.csskarma.com/blog/wp-content/uploads/turtle.jpg" alt="Turtle"></p><p>For years (and by &#8220;years&#8221;, I most likely mean &#8220;the years since I started using jQuery&#8230; maybe 2&#8243;), there&#8217;s been one aspect of jQuery that&#8217;s bugged the crap out of me, the animation speed.</p><p
class="demo"><a
href="http://www.csskarma.com/lab/animation_speed/">View demo</a></p><p>We&#8217;ve all probably seen the problem that happens in many drop down menus of varying height. We set <code>slideDown(300)</code> (or whatever you set it to) on all the submenus and leave like that. Inevitably, menus grow and shrink based on the content and we get this weird and mildly annoying behavior of really fast moving tall menus vs. shorter menus that move painfully slow just because there&#8217;s not much content in there.</p><p>This problem stems from where we set the speed of the animation; the value isn&#8217;t actually a speed, it&#8217;s how long it takes (in milliseconds, I think) for the animation to finish. So you can see why you get varying behaviors based on the element height.</p><p>It&#8217;s true, that you can use the built-in speed values like &#8220;fast&#8221; and &#8220;slow&#8221;, but if you want more fine-grained control over your animation, you&#8217;ll have to use a value.</p><h3>Problem Child <a
href="http://us.imdb.com/title/tt0100419/">&#8734;</a></h3><p>This is what our problem menu looks like all collapsed, just 2 clickable headings (<code>h2</code>) that will slide open to expose content (<code>p</code>)</p><p><img
src="http://www.csskarma.com/blog/wp-content/uploads/animation_collapsed.png" alt="animation collapsed"></p><p>Normally our jQuery would look something like this:</p><pre><code>$(function(){

$('h2').toggle(function(){
    <span>/* get the next element */</span>
    var next_element = $(this).next();

    <span>/* open it  if it's closed */</span>
    next_element.slideDown(500);
},function(){
    <span>/* get the next element again */</span>
    var next_element = $(this).next();

    <span>/* close it if it's open */</span>
    next_element.slideUp(500);
});

});</code></pre><p>Note: just example code, I didn&#8217;t check to see if it actually works</p><p>This is our menu fully expanded. As you can see, the first item has a lot more content then the second. Using the code above will make menu #1 move noticeably faster than menu #2; which, to me, creates an odd user experience. Because you&#8217;re like &#8220;Why&#8217;s is moving so slow?&#8221;</p><p><img
src="http://www.csskarma.com/blog/wp-content/uploads/animation_expanded.png" alt="animation expanded" /></p><p>So let&#8217;s see if we can&#8217;t fix that.</p><h3>Ben Healy (Solution) <a
href="http://us.imdb.com/name/nm0000615/">&#8734;</a></h3><p>What we&#8217;re looking to do here is <strong>get the height</strong> of each collapsed item, do some JS math, and set a speed (animation time) value based on the height.</p><h4>jQuery functions we&#8217;ll need</h4><ul><li><a
href="http://docs.jquery.com/Traversing/next">next()</a></li><li><a
href="http://docs.jquery.com/CSS/height">height()</a></li><li><a
href="http://docs.jquery.com/Effects/slideUp">slideDown()</a> / <a
href="http://docs.jquery.com/Effects/slideDown">slideUp()</a></li></ul</p><h4>The Code</h4><pre><code>$(function(){

	<span>/* Variables to set */</span>
	var id = '#heightCheck';
	var click_element = 'h2';
	var height_value = '100';
	var tall_menu_speed = 400;
	var short_menu_speed = 250;

	<span>/* System variables, probably don't change */</span>
	var target = id +' '+ click_element;
	var menu_content = $(target).next();

	<span>/* Hide the element after the click_element, whether it's a
	div, p, ul, whatever you choose to wrap the items in */</span>
	menu_content.hide();

	$(target).toggle(function(){
		<span>/* save the menu items in a variable */</span>
		var this_menu = $(this).next();

		<span>/* get the menu height and save it */</span>
		var menu_height = this_menu.height();

		<span>/* Calculate the animation speed based on the element height */
		/* if the height is greater than the height set above use the
		tall menu height */</span>
		if(menu_height > height_value){
			var speed = tall_menu_speed;

		<span>/* If it's smaller, use the short menu height */</span>
		} else if(menu_height < height_value) {
			var speed = short_menu_speed;
		}

		<span>/* slide the menu down */</span>
		this_menu.slideDown(speed);

	},function(){
		<span>/* this is the same but reversed to close the menu */</span>
		var this_menu = $(this).next();
		var menu_height = $(this).next().height();

		<span>/* Calculate the animation speed based on the element height */</span>
		if(menu_height > height_value){
			var speed = tall_menu_speed;
		} else if(menu_height < height_value) {
			var speed = short_menu_speed;
		}
		this_menu.slideUp(speed);

	});

});</code></pre><p>That should give you a little more control over the menu speed. I'm sure it needs to be tweaked based on the menu you're using, but the general concept is there, and it should work pretty well. I hope it was helpful. Let me know if you have any additions to the code or suggestions to improve it.</p><p
class="demo"><a
href="http://www.csskarma.com/lab/animation_speed/">View demo</a></p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/conditional-animation-speed/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Quick Tip #2  &#8211; Bringing Back Search with jQuery</title><link>http://www.csskarma.com/blog/qt2-bringing-search-back/</link> <comments>http://www.csskarma.com/blog/qt2-bringing-search-back/#comments</comments> <pubDate>Mon, 29 Jun 2009 14:29:05 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Web Development]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=546</guid> <description><![CDATA[This is something I use on all my projects now. It&#8217;s designed for a search box, but can be used with any sort of input field. The great thing about this is that the field value &#8220;Search&#8221; will only come back onBlur if the field is empty (or doesn&#8217;t say &#8220;Search&#8221;). So if you started [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.csskarma.com/images/articles/bringing-back-search.jpg" alt="article banner"/></p><p>This is something I use on all my projects now. It&#8217;s designed for a search box, but can be used with any sort of input field.</p><p>The great thing about this is that the field value &#8220;Search&#8221; will only come back onBlur if the field is empty (or doesn&#8217;t say &#8220;Search&#8221;). So if you started typing something it won&#8217;t erase your text, which is something that has always irritated me about search boxes.</p><p>Anyway, I&#8217;ve been sitting on this post for a while, but I really wanted to get it out. So here it is:</p><h5>XHTML</h5><pre><code>&lt;div id=&quot;search&quot;&gt;
&lt;form method=&quot;post&quot; action=&quot;&quot;&gt;
   &lt;label for=&quot;field&quot;&gt;search&lt;/label&gt;
   &lt;input type=&quot;text&quot; id=&quot;field&quot;/&gt;
   &lt;button type=&quot;submit&quot;&gt;go&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;<span>&lt;!--/search--&gt;</span></code></pre><h5>jQuery</h5><pre><code>$("#search input").focus( function() {
if ($(this).val()=="Search") {$(this).val("");}
});

$("#search input").blur( function() {
if ($(this).val()=="") {$(this).val("Search");}
});</code></pre><p>The word &#8220;Search&#8221; in the jQuery is case sensitive, so watch out for that.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/qt2-bringing-search-back/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>This Week in Links 12/2</title><link>http://www.csskarma.com/blog/this-week-in-links-11/</link> <comments>http://www.csskarma.com/blog/this-week-in-links-11/#comments</comments> <pubDate>Mon, 08 Dec 2008 16:47:58 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[News]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[conference]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[jquery]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=265</guid> <description><![CDATA[CSS Deployment 101 Reinhold Weber talks about how to compress a CSS file before you push it to the server. this will shave off some load time by reducing everything to one line and removing much of the white space. It also allows you to modularize your CSS without it effecting HTTP requests, because this [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.csskarma.com/images/articles/this-week-in-links.jpg" alt="article image"/></p><h5><a
href="http://reinholdweber.com/?p=37" rel="external">CSS Deployment 101</a></h5><p>Reinhold Weber talks about how to compress a CSS file before you push it to the server. this will shave off some load time by reducing everything to one line and removing much of the white space. It also allows you to modularize your CSS without it effecting HTTP requests, because this script will also combine all files into one once it&#8217;s on the server.</p><h5><a
href="http://www.cssnewbie.com/equal-height-columns-with-jquery/" rel="external">Equal Height Columns with jQuery</a></h5><p>A very useful bit of jQuery creating equal height columns. Pretty slick integration, I&#8217;ll be using this.</p><h5><a
href="http://north.webdirections.org/" rel="external">Web Directions North</a></h5><p>Web Directions is a conference I went to last January, it was very cool. Possibly the best conference I&#8217;ve been to so far. It&#8217;s coming back this February in Denver; if you have the means, I highly recommend it.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/this-week-in-links-11/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>This Week in Links 11/11</title><link>http://www.csskarma.com/blog/this-week-in-links-10/</link> <comments>http://www.csskarma.com/blog/this-week-in-links-10/#comments</comments> <pubDate>Tue, 11 Nov 2008 15:57:30 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[jobs]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[php]]></category> <category><![CDATA[sharing]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=222</guid> <description><![CDATA[Krop.com I figured with the economy what it is and a lot of web folks looking for work I&#8217;d help out and post my favorite job site, Krop.com. I like this site for a few different reasons: I found my current job there They have a very simple interface You can sign up for e&#8211;mail [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.csskarma.com/images/articles/this-week-in-links.jpg" alt="article image"/></p><h5><a
href="http://www.krop.com" rel="external">Krop.com</a></h5><p>I figured with the economy what it is and a lot of web folks looking for work I&#8217;d help out and post my favorite job site, <a
href="http://www.krop.com" rel="external">Krop.com</a>. I like this site for a few different reasons:</p><ul><li>I found my current job there</li><li>They have a very simple interface</li><li>You can sign up for e&ndash;mail alerts based on a search term. When I was looking for a job in California I signed up to get e&ndash;mailed whenever a job came up in the search that had &quot;, CA&quot; in it. So I got all the California web jobs sent to me (and a few Canadian ones). It&#8217;s very nice.</li></ul><h5><a
href="http://acomment.net/php-tutorials-utopia-13-vital-php-skills-for-every-novice-php-developer-and-solutions/378" rel="external">13 Vital Skills for Every PHP Developer</a></h5><p>There&#8217;s a lot about PHP that I just don&#8217;t remember off the top of my head and I need to look up. Luckily most of that is listed right here. This article contains things like Smarty, PayPal Integration, access control and caching with PHP.</p><h5><a
href="http://99atoms.com/post/A-jQuery-TwitterTicker-Plugin.aspx" rel="external">jQuery Twitter Display</a></h5><p>I&#8217;ll say it. I think jQuery is massively overused. But since you&#8217;re using it anyway and you want to display your Tweets, this is a plugin to do just that.</p><h5><a
href="http://www.docstoc.com/">DocStoc</a></h5><p>DocStoc is a repository for all kinds of documents. You can get everything from an example of a contract (hint hint to you freelancers) to the guitar tabs for &quot;Smell Like Teen Spirit&quot;</p><p><em>I&#8217;m not sponsored by any of these sites or services</em>.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/this-week-in-links-10/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>This Week in Links 10/27</title><link>http://www.csskarma.com/blog/this-week-in-links-8/</link> <comments>http://www.csskarma.com/blog/this-week-in-links-8/#comments</comments> <pubDate>Mon, 27 Oct 2008 16:04:50 +0000</pubDate> <dc:creator>Tim</dc:creator> <category><![CDATA[News]]></category> <category><![CDATA[Web Development]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[finances]]></category> <category><![CDATA[font]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[seo]]></category> <category><![CDATA[twitter]]></category><guid
isPermaLink="false">http://www.csskarma.com/blog/?p=213</guid> <description><![CDATA[Better CSS Font Stacks A good article on how to jazz up your stacks to try and take advantage of users who have more fonts installed. I&#8217;m all for this, and as long as it&#8217;s done carefully, can get a nice version of progressive enhancement. 5 Terrible SEO Ideas Richard Bradshaw goes over some trendy [...]]]></description> <content:encoded><![CDATA[<p><img
src="http://www.csskarma.com/images/articles/this-week-in-links.jpg" alt="article banner"/></p><h5><a
href="http://unitinteractive.com/blog/2008/06/26/better-css-font-stacks/" rel="external">Better CSS Font Stacks</a></h5><p>A good article on how to jazz up your stacks to try and take advantage of users who have more fonts installed. I&#8217;m all for this, and as long as it&#8217;s done carefully, can get a nice version of progressive enhancement.</p><h5><a
href="http://www.bradshawenterprises.com/blog/2008/10/10/5-terrible-seo-ideas/" rel="external">5 Terrible SEO Ideas</a></h5><p>Richard Bradshaw goes over some trendy (and terrible) things that are common in SEO such as: keyword stuffing, dupe content, link farms, splash pages, and cloaking.</p><h5><a
href="http://jqueryfordesigners.com/fun-with-overflows/" rel="external">Fun with Overflows</a></h5><p>I think this is a <strong>great</strong> idea (<a
href="http://jqueryfordesigners.com/demo/scrollable-timelines.html" rel="external">check out the demo</a>). It creates a very similar interface to that of <a
href="http://www.plurk.com" rel="external">Plurk</a>, the twitter competitor.</p><h5><a
href="http://www.tweetwhatyouspend.com/" rel="external">Tweet What you Spend</a></h5><p>This is a pretty cool service that uses the Twitter API to track spending. I know it can seem kind of geeky (as is reading articles about CSS&#8230;), but tracking your spending is a great way to save money, it gives you a lot of power when you know exactly how your paycheck disappears every month. Provided you don&#8217;t mind sharing your expenses with the <a
href="http://twitter.com/csskarma/" rel="external">Twitterverse</a>, this is a good service and very easy to use.</p> ]]></content:encoded> <wfw:commentRss>http://www.csskarma.com/blog/this-week-in-links-8/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 7/14 queries in 0.244 seconds using disk: basic

Served from: www.csskarma.com @ 2012-02-09 16:06:38 -->
