Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div class="box1"></div>
  <div class="box2"></div>
</body>
</html>
 
.box1 {
  background: red;
  width: 120px;
  height: 50px;
  margin-top: 100px;
  margin-left: 100px;
}
.box2 {
  background: yellow;
  width: 60px;
  height: 40px;
}
body {
  height: 2000px;
}
 
$(document).on('scroll', function(){
   var h = $('body').scrollTop();
   var b1 = $('.box1');
   var b2 = $('.box2');
  
  var x = h * 5;
  
  b1.css('transform', 'translateX(-' + x + 'px)');
  b1.css('-webkit-transform', 'translateX(-' + x + 'px)');
  
  b2.css('transform', 'translateX(' + x + 'px)');
  b2.css('-webkit-transform', 'translateX(' + x + 'px)');
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers