Neal Grosskopf Dot Com A NG Designs Site

Neal Grosskopf Dot Com Return To Neal Grosskopf's Home Page a NG Designs Site

Toolbar

  • Skip To
    • Menu
    • Content
  • Validate
    • HTML
    • CSS
    • WAI
  • Font Size
    • Small
    • Medium
    • Large
    • Extra Large
  • Account
    • Create Account
    • Login

Interact

Navigation

  • Home
  • Interact
    • Blog
    • Message Board
    • Open Links
    • Open Videos
    • Photo Gallery
    • Polls
    • Reviews
    • Geek Speak
  • Designs
    • View All Designs
    • Professional
    • Corporate
    • Templates
    • Personal
    • Club
    • NG Designs
    • Web Guides
  • Files
    • Artwork
    • Wallpapers
    • My File Downloads
  • Extras
    • Bookmarklets
    • The Magic 8-Ball
    • Career Builder RSS Feed Generator
    • Monster.com RSS Feed Generator

A jQuery Plugin To Create CSS3 Text-Shadows In Internet Explorer

  • Actions
    • View All
    • View Article Statistics
    • View User Statistics
    • Search
    • Subscribe to RSS Feed

Recent Articles:

  • Tracking Outgoing Links in Google Analytics Using Event Tracking and jQuery
  • Tracking Internal Website Campaigns With Google Analytics and PHP
  • Everything You Need to Know About jQuery's .data() Method
  • Google vs. China: How It Will Affect Web Workers
  • Don't Like The New Facebook Home Page? Fix It With 5 Lines of CSS
View All

Subscribe To Feed
loading Subscribers

I'm On Twitter loading

Dec 07

I was on the jQuery website the other day reading the documentation and as I neared end of the page I noticed one of the footer links appeared to have a text-shadow. For whatever reason I decided to inspect the element with Firebug, only to discover it wasn't using CSS3's text-shadow property. What I found was the text was actually duplicated and layered on top of the exact same text, but slightly offset.

jQuery.com Footer

This isn't exactly a new technique, I mean check out You're the Man Now Dog for probably one of the earliest examples. In any case, IE6, IE7 & IE8 do not support the CSS3 text-shadow property, and the only form of shadowing they support is the proprietary shadow filter. So I figured, why not make a jQuery plugin where you can just apply this to an element and have it automatically do all the work for you while still working in IE6, IE7 & IE8.

HTML Setup

Below is the HTML I'll apply the text shadow to:

<p><span class="shadow-me">Text Shadow</span></p>

Javascript Setup

Here is the basic plugin call. The first parameter is the color of the shadow, the second the x-offset and the third the y-offset.

$(document).ready(function(){ $(".shadow-me").textShadow("#000",1,1); });

jQuery Plugin

Finally, below is the jQuery plugin I wrote. The parent variable basically creates a random ID that I use to target the jQuery created element. I then wrap the target element in a DIV which is used as a position: relative; container. Next I set the height of that container so that it overflows correctly.

After that, I create the additional HTML element to act as a faux shadow and position it according to the parameters.

(function ($) { $.fn.textShadow = function(shadowcolor,x,y) { return this.each(function(i){ var parent = "tsw-" + Math.floor(Math.random()*100000); //Create container $(this).wrap('<div class="text-shadow-wrapper" id="' + parent + '"></div>'); //Set height of container so that it properly overflows $("#" + parent).css("height", $(this).css("font-size")); //Math.abs()?? //Add text-shadow class to initial element $(this).addClass("text-shadow"); //Adds shadow HTML element $(this).before('<span class="shadow">' + $(this).text() + '</span>'); //Positions shadow HTML element $("#" + parent + " .shadow").css({left: x, top: y, color: shadowcolor}); }); }; })(jQuery);

Examples

Below are a few examples I created with this technique. You can also view these on my demo page to see what's going on behind the scenes.

View Examples

Todos

There's a few things I'd need to improve on the plugin before it gets used in any production environment. First the shadow loses any specific font-styling applied directly to the original text. One could craft their selectors in a way that wouldn't make this a problem. Also the plugin could be improved to check against the original text's font properties and apply those to the shadow. Finally this doesn't appear to work very well if placed in between a large amount of a text. It works best as a page heading or in a nav.

Tags: css, jquery ( Add Tag )

Bookmark This Page:
  • Digg loading
  • Delicious loading
  • Re-Tweet loading
  • StumbleUpon loading
  • DZone loading
  • Snipplr
  • Script & Style

Replies:

  • Ivor Padilla
    Ivor Padilla
    #1

    Wed. December 9, 9:18:12 AM

    The shadow blur isn't available?

  • Åsk Dabitch
    Åsk Dabitch
    #2

    Wed. December 9, 2:35:12 PM

    Off to a a good start, this could be very useful

  • Patrick Thomas
    Patrick Thomas
    #3

    Fri. April 23, 1:43:52 PM

    I say, let the 50% IE market suffer....no drop shadows for them and I don't waste time and $$$ on it.

  • Tom Roggero
    Tom Roggero
    #4

    Wed. July 21, 9:21:49 AM

    i just added

    var fuente = $(this).css("font-weight")+" "+$(this).css("font-style")+" "+$(this).css("font-size")+"/"+$(this).css("line-height")+" "+$(this).css("font-family");

    and added ", font: fuente" to the last css add.


Reply:

B U I Link Font Color Edit Preview ?
Characters: 0 Textbox Size: [+] [-]
   

  • New Comment
    #5

    Sat. July 31, 1:12:54 PM

Font Size:

  • A
  • A
  • A
  • A

Search:

Places:

  • Blog
  • Message Board
  • Chat Room
  • Geek Speak
  • Open Videos
  • Reviews
  • Tag Cloud
 

Site Links

Site

  • About
  • Contact Me
  • Site Map
  • Site Search

Interact

  • Blog
  • Geek Speak
  • Message Board
  • Open Links
  • Open Videos
  • Photo Gallery
  • Polls
  • Reviews

Random Stuff

  • Hosting by FatCow
  • © Copyright 2005 - 2010
  • Modified: Friday, July 16, 2010
  • Load Time: 0.03 Seconds

Site Coded And Designed By Neal Grosskopf Using No Crappy CMS Or Themes