, jQuery. . div , , . . .
Now I have changed the plugin, and now it uses CSS3 for the shadow effect for browsers that support it, or the same div-based shadow for non-supported browsers. Here is the code:
(function($){
$.fn.dropshadow = function(settings){
var opts = $.extend({}, $.fn.dropshadow.defaults, settings);
var style = $('div')[0].style;
var isCSS3 = style.MozBoxShadow !== undefined || style.WebkitBoxShadow !== undefined || style.BoxShadow !== undefined;
return this.each(function(settings){
var options = $.extend({}, opts, $(this).data());
var $this = $(this);
if (!isCSS3){
var styles = {
position: 'absolute',
width: $this.width() + 'px',
height: $this.height() + 'px',
backgroundColor: options.shadowColor,
zIndex: options.shadowLayer,
top: ($this.offset().top + parseInt(options.distance, 10)) + 'px',
left: ($this.offset().left + parseInt(options.distance, 10)) + 'px'
};
}
else{
var boxshadow = options.distance + ' ' + options.distance + ' ' + options.blur + ' ' + options.shadowColor;
var styles = {
position: 'absolute',
width: $this.width() + 'px',
height: $this.height() + 'px',
backgroundColor: options.shadowColor,
zIndex: options.shadowLayer,
top: $this.offset().top + 'px',
left: $this.offset().left + 'px',
MozBoxShadow:boxshadow,
WebkitBoxShadow:boxshadow,
BoxShadow:boxshadow
};
}
$('<div>').appendTo($('body')).css(styles);
});
}
$.fn.dropshadow.defaults = {
shadowColor: '#DFDFDF',
shadowLayer: -1,
distance:'5px',
blur:'3px'
}
})(jQuery);
Here's how to use it:
$(window).load(function(){
$('.shadow').dropshadow({
shadowColor: '#cccccc',
shadowLayer: -100,
distance:'6px',
blur:'3px'
});
});
source
share