jquery slide out...help please :)

jquery slide out...help please :)

I'm adding a slide out box to my site, like on here  http://demo.tutorialzine.com/2010/04/slideout-context-tips-jquery-css3/demo.html

I was just wondering how i'd add opacity, so the background dims out a bit when the box opens? The javascript I have is:

  1. $(document).ready(function(){
  2. /* The code here is executed on page load */
  3. /* Replacing all the paragraphs */
  4. $('.main p').replaceWith(function(){
  5.  
  6.  
  7. /* The style, class and title attributes of the p are copied to the slideout: */
  8. return '\
  9. <div class="slideOutTip '+$(this).attr('class')+'" style="'+$(this).attr('style')+'">\
  10. \
  11. <div class="tipVisible">\
  12. <div class="tipIcon"><div class="plusIcon"></div></div>\
  13. <p class="tipTitle">'+$(this).attr('title')+'</p>\
  14. </div>\
  15. \
  16. <div class="slideOutContent">\
  17. <p>'+$(this).html()+'</p>\
  18. </div>\
  19. </div>';
  20. });

  21. $('.slideOutTip').each(function(){

  22. /*
  23. Implicitly defining the width of the slideouts according to the width of its title,
  24. because IE fails to calculate it on its own.
  25. */
  26. $(this).width(40+$(this).find('.tipTitle').width());
  27. });
  28. /* Listening for the click event: */
  29. $('.tipVisible').bind('click',function(){
  30. var tip = $(this).parent();
  31. /* If a open/close animation is in progress, exit the function */
  32. if(tip.is(':animated'))
  33. return false;

  34. if(tip.find('.slideOutContent').css('display') == 'none')
  35. {
  36. tip.trigger('slideOut');
  37. }
  38. else tip.trigger('slideIn');

  39. });
  40. $('.slideOutTip').bind('slideOut',function(){

  41. var tip = $(this);
  42. var slideOut = tip.find('.slideOutContent');
  43. /* Closing all currently open slideouts: */
  44. $('.slideOutTip.isOpened').trigger('slideIn');
  45. /* Executed only the first time the slideout is clicked: */
  46. if(!tip.data('dataIsSet'))
  47. {
  48. tip .data('origWidth',tip.width())
  49. .data('origHeight',tip.height())
  50. .data('dataIsSet',true);
  51. if(tip.hasClass('openTop'))
  52. {
  53. /*
  54. If this slideout opens to the top, instead of the bottom,
  55. calculate the distance to the bottom and fix the slideout to it.
  56. */
  57. tip.css({
  58. bottom : tip.parent().height()-(tip.position().top+tip.outerHeight()),
  59. top : 'auto'
  60. });
  61. /* Fixing the title to the bottom of the slideout, so it is not slid to the top on open: */
  62. tip.find('.tipVisible').css({position:'absolute',bottom:3});
  63. /* Moving the content above the title, so it can slide open to the top: */
  64. tip.find('.slideOutContent').remove().prependTo(tip);
  65. }
  66. if(tip.hasClass('openLeft'))
  67. {
  68. /*
  69. If this slideout opens to the left, instead of right, fix it to the
  70. right so the left edge can expand without moving the entire div:
  71. */
  72. tip.css({
  73. right : Math.abs(tip.parent().outerWidth()-(tip.position().left+tip.outerWidth())),
  74. left : 'auto'
  75. });
  76. tip.find('.tipVisible').css({position:'absolute',right:3});
  77. }
  78. }
  79. /* Resize the slideout to fit the content, which is then faded into view: */
  80. tip.addClass('isOpened').animate({
  81. width : Math.max(slideOut.outerWidth(),tip.data('origWidth')),
  82. height : slideOut.outerHeight()+tip.data('origHeight')
  83. },function(){
  84. slideOut.fadeIn();
  85. });

  86. }).bind('slideIn',function(){
  87. var tip = $(this);

  88. /* Hide the content and restore the original size of the slideout: */
  89. tip.find('.slideOutContent').fadeOut('fast',function(){
  90. tip.animate({
  91. width : tip.data('origWidth'),
  92. height : tip.data('origHeight')
  93. },function(){
  94. tip.removeClass('isOpened');
  95. });
  96. });

  97. });
  98. });