Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 29th, 2012  |  syntax: None  |  size: 1.85 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Manipulate elements of the DOM that are dynamically loaded after document loads
  2. $(document).ready(function(){
  3. $('#content img').click(function(){
  4.     var img = this;
  5.     var width = img.clientWidth;
  6.     var height = img.clientHeight;
  7.     var imgWidth = -width/2;
  8.     var imgHeight = -height/2;
  9.     $(this).wrap('<div class="box"></div>');
  10.     $('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
  11.     $('.box').animate({'opacity':'1.00'}, 300, 'linear');
  12.     $('.backdrop, .box').css('display', 'block');
  13.     $('.box').css('margin-left', imgWidth);
  14.     $('.box').css('margin-top', imgHeight);
  15. });
  16.  
  17. $('.close').click(function(){
  18.     close_box();
  19. });
  20.  
  21. $('.backdrop').click(function(){
  22.     close_box();
  23. });
  24.  
  25. });
  26.  
  27. function close_box()
  28. {
  29. $('.backdrop, .box').animate({'opacity':'0'}, 300, 'linear', function(){
  30.     $('.backdrop, .box').css('display', 'none');
  31. });
  32. }
  33.        
  34. .backdrop {
  35. position:absolute;
  36. top:0px;
  37. left:0px;
  38. width:100%;
  39. height:100%;
  40. background:#000;
  41. opacity: .0;
  42. filter:alpha(opacity=0);
  43. z-index:50;
  44. display:none;
  45. }
  46.  
  47.  
  48. .box {
  49. position:absolute;
  50. top:50%;
  51. left:50%;
  52. background:#ffffff;
  53. z-index:51;
  54. padding:10px;
  55. -webkit-border-radius: 5px;
  56. -moz-border-radius: 5px;
  57. border-radius: 5px;
  58. -moz-box-shadow:0px 0px 5px #444444;
  59. -webkit-box-shadow:0px 0px 5px #444444;
  60. box-shadow:0px 0px 5px #444444;
  61. display:none;
  62. }
  63.  
  64. .close {
  65. float:right;
  66. margin-right:6px;
  67. cursor:pointer;
  68. }
  69.        
  70. $('#content').on('click', 'img', function(){
  71.     var img = this;
  72.     var width = img.clientWidth;
  73.     var height = img.clientHeight;
  74.     var imgWidth = -width/2;
  75.     var imgHeight = -height/2;
  76.     $(this).wrap('<div class="box"></div>');
  77.     $('.backdrop, .box').animate({'opacity':'.50'}, 300, 'linear');
  78.     $('.box').animate({'opacity':'1.00'}, 300, 'linear');
  79.     $('.backdrop, .box').css('display', 'block');
  80.     $('.box').css('margin-left', imgWidth);
  81.     $('.box').css('margin-top', imgHeight);
  82. });