Guest User

Untitled

a guest
May 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /*
  2. Creates a simple drop shadow behind some text. It just duplicates the desired text element and places a copy underneath it, with a darker text color, and slightly offset.
  3. */
  4.  
  5. jQuery.fn.dropShadow = function(options)
  6. {
  7. var settings = {
  8. textColor : '#fff',
  9. shadowColor : '#808080',
  10. offsetLeft : 1,
  11. offsetBottom : 1
  12. }
  13.  
  14. if(options) {
  15. jQuery.extend(settings, options);
  16. };
  17.  
  18. // IE 6 doesn't sent the position of the shadow correctly... box model issue?
  19. if ( ($.browser.msie && $.browser.version > 6) || !$.browser.msie )
  20. {
  21. /*
  22. TODO - try to poll the text size and see if it changes, then resize the shadow accordingly
  23. this.parent().append('<span id="textResize" style="display: none;">x</span>');
  24. startSize = $("#textResize").height();
  25. */
  26.  
  27. this.each(function(){
  28. ele = $(this);
  29. position = ele.position();
  30. width = ele.width(); // need to set the width of the new element so it lines up
  31.  
  32. shadow = ele.clone().insertAfter( $(ele) );
  33.  
  34. shadow.css({
  35. top: position.top + settings.offsetLeft,
  36. left: position.left + settings.offsetBottom,
  37. color: settings.shadowColor,
  38. position: 'absolute',
  39. 'z-index': 1,
  40. width: width
  41. });
  42.  
  43. ele.css({
  44. color: settings.textColor,
  45. position: 'relative',
  46. 'z-index': 999
  47. });
  48. });
  49. }
  50. }
  51.  
  52. /*
  53. USAGE
  54.  
  55. $('.callOutStyled p').dropShadow({shadowColor: '#ababab'});
  56.  
  57. TAKES
  58.  
  59. <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
  60.  
  61. CREATES
  62.  
  63. <p style="color: rgb(255, 255, 255); position: relative; z-index: 999;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p><p style="top: 40px; left: 25px; color: rgb(171, 171, 171); position: absolute; z-index: 1; width: 185px;">Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
Add Comment
Please, Sign In to add comment