Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Crowd at a concert Parallax</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
        <div id="scene" class='parallax' data-speed="-4">
            <img src="https://ydmitry.ru/upload/blog/crowd/scene.png">
        </div>
        <div id="crowd-first" class='parallax'>
            <img src="https://ydmitry.ru/upload/blog/crowd/crowd-first.png">
        </div>
        <div id="crowd-second" class='parallax' data-speed="-2">
            <img src="https://ydmitry.ru/upload/blog/crowd/crowd-second.png">
        </div>
        <div id="crowd-third" class='parallax' data-speed="-3">
            <img src="https://ydmitry.ru/upload/blog/crowd/crowd-third.png">
        </div>
</div>
  <div class="container">
    <h1>lorem</h1>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Quidem deleniti et eum perferendis laboriosam odio, totam reiciendis non quasi repudiandae error ab aspernatur odit accusantium placeat laborum debitis nesciunt minima.
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Dignissimos voluptatem modi necessitatibus culpa error molestiae magnam distinctio sed! Consequatur quam enim accusantium nam odio expedita facere debitis optio beatae doloremque.
    Placeat voluptatibus autem dolore numquam sapiente magnam. Doloremque, modi officia, repudiandae dolorem quis, eum illum quaerat distinctio sunt hic ratione mollitia veniam error! Pariatur tempore veritatis cupiditate tenetur, tempora consequuntur!
    Possimus quae omnis quasi tenetur ipsam itaque corrupti tempore ex quia eos ratione neque voluptatum eaque, ut dignissimos ullam aspernatur porro rerum, eligendi cupiditate facilis deleniti? Minima iusto nesciunt ea!
    Aliquam iure dolorem autem officia odit quis cumque nostrum corporis obcaecati, dignissimos provident commodi inventore placeat consectetur beatae quos, id vel at laborum debitis nesciunt. Eius expedita sunt tenetur sequi.
    Quas maxime, architecto enim quam commodi hic odit consectetur sed? Labore magni fuga, consequuntur minus obcaecati autem eaque quia? Suscipit iste harum minus maiores dolores laboriosam sed accusamus cupiditate veniam!
  </div>
</body>

</html>
            
          
!
            
              * {
    margin: 0;
    padding: 0;
}

body {
    background: #1f2c2c;
    color: #fff;
    font-family: Arial, serif;
}

.container {
    position: relative;
    background: #1f2c2c;
    height: 760px;
    width: 1200px;
    margin: 0 auto;
    overflow: hidden;
}

.parallax {
    position: absolute;
}

#scene {
    z-index: 100;
}

#crowd-third {
  z-index: 200;
}

#crowd-second {
  z-index: 300;
}

#crowd-first {
  z-index: 400;
}
            
          
!
            
              $(document).ready(function(){

  var elem = $('.container'),
      pos = elem.offset(),
      elem_left = pos.left,
      elem_top = pos.top,
      elem_width = elem.width(),
      elem_height = elem.height(),
      x_center,
      y_center;


  $('.container').mousemove(function(e){

    x_center = ( elem_width / 2 ) - ( e.pageX - elem_left );
    y_center = ( elem_height / 2 ) - ( e.pageY - elem_top );

    $('.parallax').each(function(){

      var speed = $(this).attr('data-speed'),
          xPos = Math.round(-1*x_center/20*speed),
          yPos = Math.round(y_center/20*speed);

      if (yPos < 0)
        yPos = -2*speed;
     
      $(this).css('transform', 'translate3d('+xPos+'px, '+yPos+'px, 0px)');

        });

    });

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console