Guest User

Untitled

a guest
May 20th, 2014
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /*
  2. JS
  3. $(window).resize(function(){
  4. resize();
  5. });
  6.  
  7.  
  8. function resize(){
  9.  
  10. $('.backgroundImage').each(function(){
  11.  
  12. var backgroundImage = $(this);
  13. var imageWidth = backgroundImage.width();
  14. var imageHeight = backgroundImage.height();
  15.  
  16. var windowWidth = $(window).width();
  17. var windowHeight = $(window).height();
  18.  
  19.  
  20. if(imageWidth>windowWidth){
  21. var newWidth = -(imageWidth - windowWidth)/2;
  22. backgroundImage.css('margin-left', newWidth);
  23. };
  24.  
  25. if(imageHeight>windowHeight){
  26. var newHeight = -(imageHeight - windowHeight)/2;
  27. backgroundImage.css('margin-top', newHeight);
  28. };
  29. });
  30. };
  31.  
  32. */
  33.  
  34.  
  35. /*
  36. HTML
  37.  
  38. <div class="image_container">
  39. <img src="img/bg_1.jpg" alt="alt" class="backgroundImage"/>
  40. </div>
  41.  
  42. */
  43.  
  44.  
  45. /*
  46. CSS
  47.  
  48.  
  49. !important
  50. body, html {width: 100%; height: 100%;}
  51.  
  52. .image_container {
  53. position: absolute;
  54. left: 0px:
  55. top: 0px;
  56. width: 100%;
  57. height: 100%;
  58. z-index: 0;
  59. overflow: hidden;
  60.  
  61. }
  62.  
  63. .image_container>img {
  64. display: block;
  65. min-height: 100%;
  66. min-width: 100%;
  67. position: absolute;
  68. }
  69.  
  70. */
Advertisement
Add Comment
Please, Sign In to add comment