Advertisement
migsmorre

Untitled

Aug 20th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Untitled Document</title>
  5.  
  6. <style type="text/css">
  7. body{
  8. margin:0;
  9. padding:0;
  10.  
  11. }
  12. ul{
  13. margin-top:0px;
  14. margin-left:25px;
  15. margin-right:25px;
  16. padding-top:0px;
  17.  
  18. }
  19. ul li{
  20. list-style:none;
  21. overflow:hiden;
  22. height:500px;
  23.  
  24. }
  25. .parallax-background{
  26. height:600px;
  27. }
  28. .image1{
  29. background-image:url(images/image1.jpg);
  30. background-position:50% 20%;
  31. background-size:cover;
  32.  
  33.  
  34. }
  35. .image2{
  36. background-image:url(images/image2.jpg);
  37. background-size:cover;
  38. background-position:50% 10%;
  39.  
  40.  
  41.  
  42. }
  43. .image3{
  44. background-image:url(images/image3.jpg);
  45. background-size:cover;
  46.  
  47. }
  48. .image4{
  49. background-image:url(images/image4.jpg);
  50. background-size:cover;
  51. background-position:50% 10%;
  52.  
  53.  
  54.  
  55. }
  56.  
  57. </style>
  58. </head>
  59.  
  60. <body>
  61. <ul class="parallax">
  62. <li>
  63. <div class="parallax-background image1" ></div>
  64. </li>
  65. <li>
  66. <div class="parallax-background image2">asdfasdfasdf</div>
  67. </li>
  68. <li>
  69. <div class="parallax-background image3"></div>
  70. </li>
  71. <li>
  72. <div class="parallax-background image4"></div>
  73. </li>
  74. </ul>
  75. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" >
  76. </script>
  77. <script>
  78. $(document).ready(function(){
  79. var $container=$(".parallax");
  80. var $divs = $container.find("parallax-background");
  81. var thingBeingScrolled= document.body;
  82. var liHeight=$divs.eq(0).closest("li").height();
  83. var diffHeight=$divs.eq(0).height - liHeight;
  84.  
  85. var i,len,div,li,offset,myScroll,top;
  86.  
  87. var render=function(){
  88. //loop thur divs
  89. top=thingBeingScrolled.scrollTop;
  90. for(i=0,len-$divs.length;i<len;i++){
  91. //get one div
  92. div =$divs[i];
  93.  
  94. //get the parent li
  95. li=div.parentNode;
  96.  
  97. //calcute the offset top of div
  98. offset=$(div).offset().top;
  99.  
  100. //calculate the amount to scroll
  101.  
  102. myScroll=Math.round(((top - offset)/ liHeight)* diffHeight);
  103.  
  104. //apply the scroll amounth
  105. div.style.webkitTransform = "translate3d(0px,"+ myScroll+"px, 0px)";
  106.  
  107. }
  108. };
  109. (function loop(){
  110. requestAnimationFrame(loop);
  111. render();
  112. });
  113.  
  114. });
  115. </script>
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement