Archive for the ‘user experience’ Category

Javascript: Dynamically Altering CSS Properties

Tuesday, June 9th, 2009

I’ve been on a string of javascript posts, starting with Javascript: Opportunities Abound and then Javascript: Changing Class Names to Alter CSS. Well now I want to talk about a variant of altering CSS classes, and that is just altering inline style. I use this infinitely more than changing a CSS class. You can do a lot of very easy and simple interactions for the user that are really quite easy. You can show and hide divs, change background colors or images (I’ll use that to create textbox watermarks in my next post), and much more.

So either in an external Javascript file (which is called the same way as an external CSS file), or in the head of your HTML inside a <script> tag, include the following javascript:

The Javascript:

function changeInlineStyle(tagID){
   var theTag = document.getElementById(tagID);
   if (theTag.style.display == 'block')
      theTag.style.display = 'none';
   else
      theTag.style.display = 'block';
}

The javascript first takes in a string with the tag ID that you send to it in the HTML below. Then, it creates an object that represents that ID which is named theTag. Then with a simple if statement, the javascript checks to see if the object is visible. If it is, it hides it, if it is hidden, it shows it. This is great for toggling a div with certain content. You can change different aspects of style though. Try "backgroundImage" or "backgroundColor" to change background characteristics. You can mess around with any aspect of tag’s style that you want. Text color, float, width, height, whatever you want. I have found the most common ones I use are display, backgroundColor, and backgroundImage though.

Here is the HTML that goes with the JS:

<a href="#" onclick="changeInlineStyle(targetTag);">
<div id="targetTag">This div will hide when the link above is clicked</div>

Yep, simple as that! When the link is clicked, it calls the javascript function, sending over the id to identify the tag it should work with. In this case, the link targets the div below it. Simple as that! I’ll talk about textbox watermarks next. Comments? Questions?

Javascript: Changing Class Names to Alter CSS

Tuesday, May 26th, 2009

As I discussed in my previous post, Javascript: Opportunities Abound, javascript is very powerful and can be used for a wide variety of client-side interactions. One of the most useful items I’ve found for it so far (mostly because of how much I love CSS) is to alter CSS classes! And the best part is it is incredibly easy. So either in an external Javascript file (which is called the same way as an external CSS file), or in the head of your HTML inside a <script> tag, include the following javascript:

The Javascript:

function changeCSS(tagID)
{
   var currentTag = document.getElementById(tagID);
   currentTag.setAttribute("class", "secondClass");
   currentTag.setAttribute("className", "secondClass");
   return;
}

The second setAttribute function is for certain versions of IE that for some odd reason (IE sucks) setting the class through javascript does not always function properly. I personally have not noticed this issue with IE6 or IE7, and IE5 is tops 1% of your users, so you can probably leave it out, I’ve just seen other people using it…

And now the HTML that goes with that JS:

<a href=”#” onclick=”changeCSS(targetTag);” id=”targetTag” class=”firstClass”>Adjust link CSS</a>

Yep, simple as that! When the link is clicked, it calls the javascript function, sending over the id to identify the tag it should work with. In this case, the link is adjusting it’s own CSS, but it can work on anything else in the page. But what if you want the link to work both ways, to be able to change the CSS class of an object back and forth instead of just one direction? Try this on for size, a simple if statement in your JS function (the same HTML will do)

The New Javascript:

function changeCSS(tagID)
{
   var currentTag = document.getElementById(tagID);
   if (currentTag.className == "firstClass")
   {
      currentTag.setAttribute("class", "secondClass");
      currentTag.setAttribute("className", "secondClass");
   }
   else
   {
      currentTag.setAttribute("class", "firstClass");
      currentTag.setAttribute("className", "firstClass");
   }
   return;
}

And that’s that! Simple right? It is also possible to just change a specific aspect of the CSS instead of the entire class, but I’ll talk about that in a future post. Comments? Questions?

Javascript: Opportunities Abound

Tuesday, May 19th, 2009

Javascript is a useful coding language that creates “client-side” changes to a website. It is really a great tool for simple and yet amazing interactivity on your website. Now for those of you who are used to only coding with HTML and CSS, Javascript will be quite a jump for you. Where HTML and CSS apply simply to content and layout, javascript can be very heavy on logic, something that typical computer programming is founded on. So be aware that JS could be a very big change for you.

So what can you do with JS? You can automatically rotate through images, or let users rollover thumbnails to enlarge a main photo. You can change text or even the styles that apply to text or other layouts. You can apply a simple watermark to a text box to indicate what users should do with it. You can sort tables or have fantastic animation effects to coincide with user actions. Have you ever encountered a popup window that greys out the background? Yep, that’s javascript (often combined with a few other fancy things such as AJAX, but no need to worry about that). There are really an endless number of options, many of which are pre-written to make your life easier! Here are some great resources for pre-written JS:

1. JQuery and JQuery UI are fantastic libraries of pre-written javascript. JQuery is an open-source (free for the masses) series of core JS files.The public then uses this open source base to build plugins that can do everything you could possibly imagine for client-side scripting. I’ve used jquery plugins on collegeprowler.com for a content slider and table sorting just to name a few items. JQuery UI is a subset of JQuery that focuses on very cool animation effects. I’ve used this (again at College Prowler) to implement an accordion (multiple items where only one is visible at a time), sliding content boxes open and closed, and selection sliders, again to name a few. Great tools, and incredibly easy to implement! Be aware though, because it is open source, a lot of the plugins you end up using can be very finicky on your site…

2. Carousels and Content Sliders are a great way of exposing users to a lot of content without overpowering them with options. A lot of people choose Flash for the same purpose, but flash is awful for SEO purposes, is limited because not all of your users will have it installed on their computer, and is more difficult to update. I’ve found two great carousels that can be applied to either photos or content, and have a lot of customization abilities. Check out jcarousel by Jan Sorgalla, or for a slightly lighter version (the one I ended up using) take a look at jcarousellite. Another one I’ve found out there is at cssglobe.com, which seems pretty sweet as well.

3. Popup Boxes are one of the best javascript tools you’ll ever find. They also are one of the only ones you’ll ever find yourself contemplating paying for. Even though most web users hate the idea of popup windows, popup boxes are entirely different. When used in response to a user action, the popup box offers great opportunities for what you can provide your users with, without navigating them away from a page. They can login to a site that requires registration, they can fill out forms without being forced to have the form take up space on the regular page, or they can view slideshows of images, all without feeling like they’ve left the page that they felt comfortable enough on to click a link. The two best implementations of popup boxes (or shadow boxes or lite boxes as I’ve also heard them called) are Highslide and Lightview. I have more experience using Highslide, but I think Lightview is very well made and looks gorgeous. I had found Lightview by accident some time ago, and when trying to relocate it for this post, I found a listing of all the JS popups out there here. Careful, I haven’t tested any of them.

Those are just a handful of examples of pre-written JS that you can use. In upcoming posts I’ll write a little bit about simple JS that you can implement easy peasy on your own without any coding background.

Google Analytics

Tuesday, April 14th, 2009

Google Analytics is an amazing tool for web designers and web developers. There are really four different types of things you can do with Google Analytics, and I’m here to write about each one, and some of the benefits of them, as well as a few downsides.

1. Enhance your user experience: Google analytics has tools to track the types of users you are getting. You can look at their location (in the world), their computer specs (computer type, screen size, operating system, browser/version), their viewing trends (page views, bounce rates, time on the site), and much more.

So why is this helpful? It allows you to design your site around your users. You know what browsers and versions they are using, so you can decide how much time to spend cross browser testing. You know what screen sizes your users are using, so you can figure out how wide you want your designs to be. You can see when you launch major changes to your site what happens to your user trends (did it cause an increase or decrease in the positive experience of your users). But these are all very broad things, let’s get more specific.

2. Test and improve specific content: Google analytics takes the first benefit a step further by allowing you to look at most of the above data and more with specific pages and sections of your site. This will allow you to test out smaller changes to your site by looking at user trending and navigation on specific pages or new sections that you just launched or changed.

So why is this helpful? Imagine you just put up a new section of your site that is a little more alternative to the standard navigation you have throughout the rest of your site, or the design is a bit more energetic and you aren’t sure how it will be received. Now, say a week after your launch, you can go back and see how your users interacted with the new section. You can see where they came from in the site to get there, what they did there, when they left, and where they left to go to. You can compare the visitor trends with the overall site averages and get a feel for whether the new design and/or navigation is an improvement to your site, or a detriment. It can then guide future changes to that section, or even the rest of your site!

3. Pimp out your SEO efforts: With the “sources” section of Google Analytics, you can track where your users are coming from, and how they are finding you. You can see how many users are coming in directly (typing in your web address or using a bookmark), through referring sites (external links), or through search engines. Then you can look at keywords that people used to land on specific pages within your site, or the site in general.

So why is this helpful? If you have been trying to up your SEO, then you can see how often people are linking to you (based on the rate of referring sites) and how effective you are at certain keyword searches that you are trying to optimize for. Knowing what people already land on your for and teach you what your site is doing well, and help you decide what other keywords you might want to focus more on.

4. Make some moolah: Lastly, Google Analytics allows you to track sales and other goals within your site. If you have specific items you are trying to sell, you can put in a specific goal that tracks it. Then you can see the paths those users took to get to that sale and optimize for it even more. To be honest, I haven’t focused on these tools much myself. For my own website, I don’t have much of a need for it with all the other customization options. For my work at College Prowler, though we do have sales, I tend to focus more on the user experience considering that is where my background is, and my boss looks at everything, including the sales “goals” and “ecommerce” options.

All of these sections have some additional benefits that Google Analytics is still testing out, in particular the “advanced segments” tool. This tool allows you to set up segments of your visitors or your site so that you can get even more detailed with your website’s statistics. Say you have too main sections of your site, and though they sometimes cross over with users, they are often relatively separate. You might want to see just what one half of the users are doing, as compared to the other half, because they really represent two completely different user bases. Again, it allows for even more customization to your user. There are some downsides to this tool though. In particular, you can create segments, but you can’t share them with co-workers that might be on the same analytics account, they are only available to you. I already emailed Google months ago and complained about this, but they are slow to respond to that kind of stuff. I think sometimes they pretend to be all focused on usability, but in reality, they lose that focus too often…

One more downside to Google Analytics is the slight inaccuracy of information. Data is never 100% accurate or reliable. This is a problem with really small sites where small differences can really cause issues with the data (because of low statistical power). Still, take everything you see with a grain of salt, but also put some trust in it. If anything, it will lead you in specific directions for real user testing! Overall though, fantastic tool!

Cross Browser Testing

Wednesday, February 11th, 2009

If you are making a website, you absolutely need to test it across browsers. This need increases even more when you use CSS heavily for your layout and other styling. Why you ask? Well, different browsers read CSS differently. In particular, Internet Explorer (IE) is awful because Microsoft doesn’t feel the need to ascribe to web standards. So here are some suggestions to get your started with your cross-browser testing:

1. Download every major browser to test your site in. Essentially, you should be working with Firefox, Internet Explorer, Safari, Chrome, and Opera. Opera is used by about 3% of internet users, and is the least common of the five mentioned here. There are also other browsers, but usually you need to stop somewhere, and I think Opera is a good place to end.

It might help to set yourself up with Google Analytics so you can know what percentage of your users are using what browsers. It will even break it down further into what version your users have, which brings me to my next point.

2. Make sure to test both IE7 and IE6. Internet explorer 6 and 7 are vastly different. Soon, IE8 will be out of beta testing and will be yet another version that needs to be tested. This is the biggest pain you’ll encounter. IE7 is actually pretty good at complying with web standards, but IE6 is like a death trap. The problem here is obviously you are only allowed to have one version of Internet Explorer on your browser at any given time. So, either install a virtual machine (much to techie for myself) or keep setup files for both IE6 and IE7 around, and just uninstall and reinstall (which is annoying, but it does the trick). Why must we go through such painful agony just to make sure our site looks good? Well, sadly, too many PC users don’t let Windows automatically update for them, leaving about 25% of IE users still with version 6. This is of course sensitive to the date of this post and will slowly decrease. Overall, in the past 6 months, I’ve found users of my company’s website go from about 18% IE6 users to 14%, which isn’t even statistically significant. Bottom line, test in both because they are vastly different!

3. Try out some of the free cross-browser compatibility testing tools out there. There are a lot of them, but most just want your money, and most aren’t very great if they are free. Short of shelling out some money, your best bet is probably browsershots.org. However, last I checked they limit you to one page (with every browser imaginable though). However, this requires you to have your site live when you test, whereas installing the browsers on your computer allows you to test offline.

4. Keep an eye out for common errors with specific browsers. The more you test, the better feel you’ll get for the flaws of different browsers. You’ll learn that the default margin on paragraph tags is different in IE than it is in other browsers. You’ll learn that min-height and min-width attributes do not function on IE6. As you come to figure out these flaws, you’ll be able to preempt them by writing clean and efficient CSS. This doesn’t completely eliminate the need to cross-browser test, but it certainly will make the process go a lot quicker.

When I was studying at CMU, I learned the mantra of usability research, “The user is not like me”. It is so true that it’s cliche, but it also applies to web design. You just can’t assume that your users see the same thing as what you see unless you go about finding out how they see it! Different browsers display code differently. Account for all your users or suffer the consequence and lose some of them to layout bugs…

Bloggerrific powered by WordPress | minimalism by www.genaehr.com | edited by David J Rush | Entries (RSS) and Comments (RSS).