Advertisement
Botchy

Parallax Website

Aug 12th, 2014
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. body {
  5. margin: 0;
  6. padding: 0;
  7. }
  8. ul {
  9. margin: 0;
  10. padding: 0;
  11. }
  12. ul li {
  13. list-style: none;
  14. overflow: hidden;
  15. height:600px;
  16. position:relative
  17. }
  18.  
  19. .parallax-background {
  20. height:700px;
  21. }
  22.  
  23. .lens {
  24. background-image:url('images/lens.jpg');
  25. background-position: 40% 100%;
  26. }
  27. .flower {
  28. background-image:url('images/flower.jpg');
  29. background-position:50% 60%;
  30. }
  31. .Park {
  32. background-image:url('images/Park.jpg');
  33. background-position: 80% 100%;
  34. }
  35. .headphones {
  36. background-image:url('images/headphones.jpg');
  37. background-position: 50% 100%;
  38. }
  39.  
  40.  
  41. ul li .subcontent {
  42. position:absolute;
  43. top:100px;
  44. left:100px;
  45. colour:#FFF;
  46. font-family:Arial, Helvetica, sans-serif
  47. }
  48. h1 {
  49. font-size:70px;
  50. margin-bottom:0px;
  51. }
  52. h2 {
  53. font-size:56px;
  54. margin-bottom:0px;
  55. }
  56.  
  57. </style>
  58.  
  59.  
  60. </head>
  61.  
  62. <body>
  63.  
  64. <ul class="parallax">
  65. <li
  66. <div class="parallax-background flower"></div>
  67. </li>
  68. <li>
  69. <div class="parallax-background lens"></div>
  70. <div class ="subcontent">
  71. <h1>Sample Text</h1>
  72. <h2>Hey there</h2>
  73. </li>
  74. <li>
  75. <div class="parallax-background park"></div>
  76. </li>
  77. <li>
  78. <div class="parallax-background headphones"></div>
  79. </li>
  80. </ul>
  81.  
  82.  
  83. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
  84. <script>
  85.  
  86. (function($) {
  87.  
  88.  
  89. var $container = $(".parallax");
  90. var $divs = $container.find("div.parallax-background");
  91. var thingBeingScrolled = document.body;
  92. var liHeight = $divs.eq(0).closest("li").height();
  93. var diffHeight = $divs.eq(0).height - liHeight;
  94.  
  95. var i,len,div,li,offset,scroll,top;
  96.  
  97. var render = function() {
  98.  
  99. //thing we're scrolling
  100. top = thingBeingScrolled.scrollTop;
  101.  
  102. //loop through divs
  103. for(i=0,len=$divs.length;i<len;i++) {
  104.  
  105. //get one div
  106. div = $divs[i];
  107.  
  108. //calculate the offsetTOP of div
  109. offset = $(div).offset().top;
  110.  
  111. //calculate the amount to scroll
  112. scroll = Math.round(((top - offset) / liHeight) * diffHeight);
  113.  
  114. //apply the scroll amount
  115. div.style.webkitTransform = "translate3d(0px,"+scroll+"px,0px)";
  116.  
  117. }
  118.  
  119.  
  120. };
  121.  
  122. (function loop(){
  123. requestAnimationFrame(loop);
  124. render();
  125. })();
  126.  
  127. })(jQuery);
  128.  
  129.  
  130.  
  131. </script>
  132.  
  133.  
  134. </body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement