James Player 11 Dec 2009
Here is an example of a div with the drop shadow class applied to it.
To get it to work:
If you would like to use your own dropshadow images:

The important thing here is to make sure the 4 corner images are all squares that are the same size and their borders line up with each other. The side images need to be as thick as the drop shadow, with the outsides lining up with the outsides of the corner images. The top and bottom images can be any width (as they get repeated horizontally) and the left and right images can be any height (as they get repeated vertically).
$('.ds').dropshadow();
$('ds_alt').dropshadow({
path_to_images: "/images/different-looking-dropshadow",
shadow_size_top: 6,
shadow_size_right: 8,
shadow_size_bottom: 10,
shadow_size_left: 8,
corner_size: 26
});
The above will draw the default styled dropshadow on anything with a class of "ds", and will draw a different looking dropshadow (one that you created) on anything with a class of "ds_alt"
Cheers
James
Read the next post - Chunked transfer encoding and onDOMReady
11 comments submit a comment
Dave
This is brilliant James. Cheers.
Matt Sanders
Not a bad Idea.. Good post. I myself have dropped supporting detail oriented features like these for esthetics in browsers that do not interpret css3 specs. Box Shadow is what I've been using for a while now and we've had a great turn-around for explaining why things like this won't work in say IE6 - IE8. However, if the client requests that visuals like this be present in one or all of those browsers we implement something like this.
What are your thoughts?
James
Hi Matt
Thanks for your feedback :)
Yeah box shadow definitely makes things easy, and it would be great if IE came to the party with CSS3. Unfortunately the reality right now is that the majority of our users use IE. Springload is quite design focused, so to say to a client (or the designer :P) that the majority of their users will not be able to view some of the elements in the design isn't really acceptable.
Hence we try and create these types of tools to make tricky designs easier to build.
Cheers!
James
Chris Barrett
Hi,
Great write up.
One question is how do I apply this to multiple div's on the same page?
Thanks
Chris
James
Hi Chris
You need to add it to a jQuery object. Eg if you want everything that has a class of 'ds' to have a drop shadow then you need to use $('.ds').dropshadow()
Cheers
James
Tom
Hey,
How could I get this to work with objects? Without wrapping them in a div of course... Tried mucking around with display properties but no luck.
Cheers,
Tom.
James
Hi Tom
Hmmm it currently works by adding 8 images inside of the tag and positioning absolutely to the parent. Since you can't add images inside of a self-closing tag that's gonna make it quite hard. One thing I might try is if it's a self closing-tag then the script wraps it in a div (that matches the dimensions of the self-closing tag) and adds the images inside the div.
Will get onto this soon.
Cheers
James
James
Have fixed this now so that it works with self closing tags such as images
Dave
Hi
First great plugin!
Am using it together with JQueryUI.resizable and when resizing an element it breaks the shadow. So I added a remove_shadow method to your plugin to make it work.
Here's the solution:
//remove_shadow
$.fn.remove_shadow = function () {
return this.each(function () {
$("img.shadow").remove();
});
};
//Using it with JQueryUI.resizable
$("("#divBox1")
.resizable(
{
start: function (event, ui) { $("#divBox1").remove_shadow(); },
stop: function (event, ui) { $("#divBox1").drop_shadow(); }
});
James
Nice one Dave!
Sharleena
This makes everything so completely paliness.