Archive for the ‘Effects’ Category

May 13

How To Zebra-Stripe Tables Using CSS and jQuery

Zebra Stripes DemoAs I was browsing my ridiculously large and disorganized RSS feeds a few days ago, I came across a very interesting article that discusses the “benefits” of using zebra-striping on tables. The article was titled Zebra Striping: Does it Really Help? and it was published on A List Apart. In short, the author of the article discusses the use of zebra-striping, its history, and the benefits which are associated with its use. Furthermore, she describes and attempts to make sense of a small experiment carried out by herself in order to test the “benefits” linked to zebra-striping. The article concludes with the author’s assesment of zebra-striping as valuable in terms of visual appeal but with little to no influence on usability. As a concluding statement she writes, “At the end of the day, the decision about whether to use zebra striping probably comes down to a subjective assessment of likely gains versus the cost of implementation.” So, let’s make the cost of implementation minimal by using some simple jQuery and CSS. Before we begin, here is a sneak peak at the final result.

jQuery Zebra Stripes Script

There are many ways to implement a zebra-striping script using jQuery, and I will demonstrate one of them. The following approach uses a function, which takes two (optional) parameter and creates a specified CSS class for all the even rows of a given table. However, if the function is called without any parameters all even rows on tables will be given the class “even-row.” Here is what the script looks like:

  1. $(document).ready(function()
  2. {
  3.     stripeTable();
  4. });
  5.  
  6. function stripeTable(table_name, class_name)
  7. {
  8.     var target;
  9.  
  10.     if(table_name && class_name)
  11.     {
  12.         target = table_name + " tr:even";
  13.         $(target).addClass(class_name);
  14.     }
  15.     else
  16.     {
  17.         target = "table tr:even";
  18.         $(target).addClass("even-row");
  19.     }
  20. }

Note: the above script is calling the function with no parameter and thus will reset to the default rules.

Add Some Style

Now that our script is complete and working, let’s add some color to the newly created class, “even-row.” Remember that this class name is given because we did not specify parameters when we called the function on the script above. So, here is what the “even-row” CSS for the demo looks like:

  1. #content table tr.even-row td
  2. {
  3.     color: #c76400;
  4.     background: #e6e6e6;
  5. }

Note: the ID content is targeting a div of the same name on the example file. Thus, when implementing your own CSS rules remove it.

Use, Installation, and Download

In case you overlooked the sneak preview link at the beginning of this post, take a look at the script in “action” by clicking this demo link. This script is free for your use or modification. However, you need to download and install jQuery for the zebra-striping to work. In other words, the of your document will have to include the following files and look something like this:

  1. <script type="text/javascript" src="[YOUR PATH]/jquery.js"></script>
  2. <script type="text/javascript" src="zebra_stripes.js"></script>

In any case, enough talking (writing), download the script and enjoy!

zebra_stripes.js

May 01

W3C Valid Buttons, A jQuery Approach

jQuery Script SolutionThere are many people who consider the W3C valid buttons as good indicators of a web designers’s understanding and attention to Web Standards. Although, this may not be entirely true, it is a reasonable and understandable way of thinking. Thus, almost every site built these days will display a valid link to the W3C’s validation app somewhere in the site (more often than not in the “footer” section). However, most designer will refrain from using the W3C provided valid buttons and will instead cook a textual or visual solution of their own. But wouldn’t it be nice if you could use these somewhat-iconic buttons only when needed? Wouldn’t it be nice if they were less obtrusive and had a place in your design? If these inquiries gave you a sense of excitement, take a look at the demo and read on.

A jQuery Approach

For those of you who are long time readers, it comes with no surprise that I have chosen jQuery for this tutorial. For those of you who are new, visit the jQuery homepage and prepare yourself to be amazed by this versatile and lightweight java framework.

There are two main problems with the W3c valid buttons, which prevent most designers from using them. Firstly, the color choices … rather, the lack of color choices for the buttons makes it hard for it to blend with any design. Secondly, unless the site being built is a W3C site, chances are the design will have a more 2.0 look. In other words, unless the design of your site is outdated, these buttons will clash with your current design.

My solution to these problems is rather simple (thanks to jQuery), hide the buttons unless needed. In other words, use jQuery to append the W3C button(s) to your validation link(s), position it above the link(s), and animate them. In order to have a better sense of this technique, take a look at the demo.

Ready To Use Script

If you wish to download the script, scroll to the end of this post and click on the download button. However, before you hurry away with a big smile in your face here are a few things you should know (AKA how-to):

  1. jQuery is needed for the script to work.
  2. You will need to add one of the following classes to your validation links:
    • valid_html
    • valid_xhtml
    • valid_css

Note: the .js file is set to work with the valid_xhtml and valid_css classes. If you wish to use the valid_html class instead of the valid_xhtml one, uncomment that line of code and viceversa. Also, if you are using this script with WordPress make sure to read my Using jQuery with Wordpress post.

Download & Copyright Things

The script is free for you to use, modify, or destroy (hopefully not the latter). But recognition or a link back is always well received. Please make sure to leave any thoughts or problems you have with the script. Enjoy!

Download Script

March 04

Mootools Style Sidebar Using jQuery

I know, the script is not here anymore, but don’t panic! You can find this and other great tutorials over at nettuts.com.