Fancy Drop Cap – Part 1
Introduction
Last spring when I implemented a new design for my weblog, I wanted to use a fancy drop cap for the first letter of the first paragraph of the first post of each page. There are all sorts of ways to make a drop cap happen, but since I was reading Jeremy Keith's excellent book DOM Scripting at the time, I thought I'd do it that way. The DOM scripting method that I put together had some important benefits for me at the time:
- It used an image, so I didn't have to worry about installed fonts on users' machines
- The HTML source stayed intact, so search engines wouldn't trip over a first word with a missing first letter.
- It degraded nicely, so if users had JavaScript or images or both turned off, everything would still look fine, just a little less pretty.
Now that I'm learning jQuery, I thought I'd revisit my code and see if I could tidy it up a bit, the jQuery way.
Image Set
I first put together a set of images, one for each letter of the alphabet, using a font from the Dieter Steffman collection at typOasis. If you don't want to go through the laborious process of converting letters into images, you can download mine (20KB zip). See the letter "A" floating to the right of this paragraph for an example.
Setting up the Code
Instead of putting all of the code in a $(document).ready() function, I created a separate function and just called it inside $(document).ready():
- swap_letter();
- });
- function swap_letter() {
- //all the code goes here
- }
Now we can get down to business.
Insert Image Here
The easiest part of the process was inserting the image, because jQuery makes it almost effortless. Read the rest of this entry »















