A LIST Apart: For People Who Make Websites

No. 266

Discuss: CSS Sprites2 - It’s JavaScript Time

Pages

 <  1 2 3 4 5 >  Last »

21 ANIMATED GIFs?

Call me a silly billy, but wouldn’t this be achievable with no jQuery using animated GIFs as background images to the link? (Dave knows my fondness for the animated GIF.)

posted at 03:54 pm on August 26, 2008 by Bruce Lawson

22 Old school ALA style!

Thanks fo a very detailed practical quality article!

I haven’t looked at it in detail yet, but I know from experience (implementing a fade in/out on text links for the nav on my site) that making the fades behave nicely can be a little bit of a headache (they tend to keep on fading in/out long after your mouse is gone if you pass over a few times in a row…).

I’m surprised some people would complain about the fact that it “doesn’t add anything” in terms of usability and therefor dismiss the whole thing as pointless. This technic doesn’t “remove” anything either… and it sure looks nice… If you think it’s pointless, you must not listen to your clients very carefully… ;)

Thanks Dave, I’ll make sure to go over the details this weekend and see how you’ve implemented it :)

posted at 04:14 pm on August 26, 2008 by Yann B

23 jQuery all the way

Being a long term jQuery user I’d go all the way and make the generateSprites function a jQuery plugin. Would look like the following:

$(‘ul.nav’).sprites(‘current-’, true, 150, ‘slide’);

posted at 04:22 pm on August 26, 2008 by Klaus Hartl

24 CSS Animations

I just remembered all the confusion and hatred that CSS Animations have caused a couple of months ago when they were proposed by Apple.

And here – a whole A List Apart article at length explaining how to implement in a lot of non-semantic Javascript code something, that is a purely design decision and could be done with the above-mentioned technologies in two lines. Sigh!

posted at 04:33 pm on August 26, 2008 by Jakub Nesetril

25 Untitled

The articles states, “The most compact version of jQuery weighs in at 15k.”
But this is only for the minified, g-zipped version which may not be a viable choice for many. Plus the time to decompress must be taken into account.
jQuery’s full size is 97kb.
And in practice, there is little difference between the full version; the minified and g-zipped version; and the packed version. (The last choice created with Dean Edwards Packer)
In all but the full version there is overhead related to decompression.

The creator of jQuery, John Ressig, thoroughly discusses the the trade-offs here:
http://ejohn.org/blog/library-loading-speed/
Also, a recent study by Yahoo surprisingly found that 40-60% of Yahoo!’s users visit with an empty cache.
http://yuiblog.com/blog/2007/01/04/performance-research-part-2/
Ressig addresses this issue as well:
“…according to Yahoo’s research on caching, approximately 50% of users will never have the opportunity to have the page contents be cached. Thus, making sure that your page loads quickly both on initial load, and subsequent loads, should be of the utmost importance.”

The article understandably puts the best face possible on the download costs but be aware.

posted at 05:29 pm on August 26, 2008 by Richard Fink

26 For the Prototype/Lowpro people out there

In case anyone cares, I re-wrote the JS as a Lowpro behavior class. It requires Prototype, Lowpro and the Scriptaculous Effects file be included first. It’s here if you want it:

http://farrellit.com/js/navsprites.js

You activate it like this:

Event.addBehavior({
‘.nav’: NavSprites(‘nav’, ‘current-’, 150, ‘slide’)
});

See it in action here:

http://farrellit.com/testing/

Main advantage is that it’s a single event listener using event delegation. I also have a Jquery/Lowpro version but that is a pretty niche group.

posted at 05:32 pm on August 26, 2008 by Daniel Farrell

27 Proper jQuery Optimization

Not to go over this again, but your initial jQuery could be redone in a much cleaner way — sans regex. The current section designation should be attached to the appropriate element as the “current” class, not as an odd hyphenated combination in the parent class. Also, if the page is built dynamically the list will be made in a loop and the class assignment can happen much easier there.

Assuming the “current” class is attached to the list elements, not the parent list:

$(’.nav’).children(‘li’).each(function() {
    if (!$(this).hasClass(‘current’)) {
        $(this).children(“a”).css({backgroundImage:‘none’});
    }
});

posted at 06:06 pm on August 26, 2008 by Michael Thompson

28 Cripes

Sorry for the non-breaking muddles in my post above. Proper code:

$(’.nav’).children(‘li’).each(function() { if (!$(this).hasClass(‘current’)) { $(this).children(“a”).css({backgroundImage:‘none’}); }
});

Also, the reason the submit button can’t be clicked is because the syndication paragraph is jumping over top of it.

posted at 06:09 pm on August 26, 2008 by Michael Thompson

29 Feedback responses

I’m going to try and address some of the questions and comments that popped up overnight.

First, the ALA submit button — as Jeffrey mentioned, we’re on it. I think we’ve got a fix worked out, stay tuned.

Jens Meirt, Florian Schmitt, and anyone else wondering why this might be needed – let’s keep in mind that modern operating systems have been adding more and more simple UI animation effects for ages. Think of the way a hidden Apple dock will slide in, or the way way Exposé quickly moves and scales windows, or window minimization effects, and so on. These are little UI details that may not strictly be necessary, but the transitions aid a user’s ability to keep track of what happens one minute to the next when the screen quickly changes, where a non-animated immediate transition could be quite confusing. Can we lump animated navigation hovers into the same category? That’s probably a subjective decision. I’d argue that if we’re going to bother defining :hover states at all, it’s nice to have the option to do something more than a binary on/off transition. Hence, this article.

@Marco van Hylckama Vlieg, and anyone else noticing the glitchy third example in the article – yeah, this one certainly wasn’t perfect. I acknowledged later in the article that jQuery’s animate function causes a bit of randomness in that example (see “Other Considerations” heading). I’m now wondering if it might be possible to hide the overlap with a bit of overflow:hidden magic; didn’t think of it at the time, but it might be worth digging in a bit more.

Jason W, Rowan W, and anyone else concerned about the opacity: 0.9999 addition – the problem with that NOT being there is that on hover, most browsers will cause the rest of the text in the page to flash in between anti-aliased and sub-pixel anti-aliased text during the animation. I’m pretty sure this is a browser bug, and if I understand the nature of it, it’s not an easy one to solve. The fix is sort of a lesser of two evils choice, but for now it’s the best we’ve got.

David Tapper, Reimar Servas, and anyone else concerned about the click+hold+move the cursor out of the link glitch – yep, we were aware of this one too and I had a last-minute addition to the article that doesn’t seem to have made it in explaining it. This behaviour is actually similar to how Firefox treats active links when you move the cursor out of a clicked link, believe it or not. The difference is that you can click elsewhere in the page to de-activate the regular link, whereas with Sprites 2 you have to click the link again. So, not ideal, and a bug, and thanks for your suggested fix David Tapper!

posted at 06:58 pm on August 26, 2008 by Dave Shea

30 More responses

Christoph Tavan, Michael Thompson, and anyone else suggesting further optimizations for examples 2 through 4 – I haven’t looked closely at your suggestions yet, but just I’ll point out that the early examples are building up to the later examples, and the final code is what we’re more interested in optimizing. Example 2 leads into example 3, so writing the first example without keeping in mind the conditionals we’ll need in the next example (or later), then having to explain each time why we changed the earlier code would make the prose a lot more clunky. Your suggestions may avoid this of course, so ignore me if I’m just stating the obvious again.

@Bruce Lawson – I’m not sure if you’ll believe me, but I tried exactly that about 4 years ago and found out then that browsers will only play endlessly looping animated GIFs as expected. For one-time animations that stop after a few frames, they’ll play the animation when the image loads and then stop, without re-triggering the animation on each mouseover. So, good idea, but foiled by the browsers once again!

@Jakub Nesetril – I don’t think I can disagree with you on that sentiment.

@Richard Fink – Thanks for the links, I didn’t have that data available when writing. Decompression is certainly another factor to keep in mind.

@Daniel Farrell – good stuff!

posted at 07:24 pm on August 26, 2008 by Dave Shea

Pages

 <  1 2 3 4 5 >  Last »

Got something to say?

Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.

Create a new account or sign in below if you’d like to leave a comment.

Remember me

Forgot your password?

Subscribe to this article's comments: RSS (what’s this?)