JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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)');
});
});
});
Also see: Tab Triggers