Advertisement
KarimMesallam

Untitled

Jun 29th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#" class=" js cssanimations" title="" autocomplete="off">
  3. <head>
  4.   <meta charset="utf-8" />
  5.   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  6.   <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
  7.   <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>
  8.   <script src="http://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.4/TweenMax.min.js"></script>
  9.   <style>
  10.     body {
  11.       height: 2000px;
  12.       position:relative;
  13.       margin:0;
  14.       padding:0;
  15.     }
  16.  
  17.     div.background-image {
  18.       position:relative;
  19.       height:50%;
  20.       width:100%;
  21.       background-image: url('http://previews.123rf.com/images/lucvar/lucvar1205/lucvar120500028/13758606-Landscape-with-portrait-orientation-of-a-beach-with-people-bathing-walking-or-lying-on-the-beach-in--Stock-Photo.jpg');
  22.       background-size: contain; /* Can add cover instead of contain if needed, or specify the width and height */
  23.       background-position:center center;
  24.       background-repeat: no-repeat;
  25.       background-attachment: fixed; /* This is the trick */
  26.     }
  27.  
  28.     .img_wrap {
  29.       position: absolute;
  30.       width: 500px;
  31.       height: 1000px;
  32.       top: 0;
  33.       left: 50%;
  34.       margin: 0 0 0 -250px;
  35.       overflow: hidden;
  36.     }
  37.  
  38.     #img{
  39.       position: absolute;
  40.       display: block;
  41.       top: 0;
  42.       left: 0;
  43.     }
  44.   </style>
  45.   <script>
  46.     var latestKnownScrollY = 0,
  47.             ticking = false;
  48.  
  49.     function onScroll() {
  50.       latestKnownScrollY = window.scrollY;
  51.       requestTick();
  52.     }
  53.  
  54.     function requestTick() {
  55.       if(!ticking) {
  56.         requestAnimationFrame(update);
  57.       }
  58.       ticking = true;
  59.     }
  60.  
  61.     function update() {
  62.       ticking = false;
  63.  
  64.       var currentScrollY = latestKnownScrollY;
  65.       document.getElementById("img").style.transform = "translate(0, "+ currentScrollY+"px)";
  66.       document.getElementById("img").style.WebkitTransform = "translate(0, "+ currentScrollY+"px)";
  67.     }
  68.  
  69.     /* No need to process such a function using JS
  70. //    window.addEventListener('scroll', onScroll, false);
  71.   </script>
  72. </head>
  73. <body>
  74. <div class="background-image">
  75.  
  76. </div>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement