Pen Settings

HTML

CSS

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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!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>
              
            
!

CSS

              
                * {
    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;
}
              
            
!

JS

              
                $(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

Console