css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <h1>Creating a Sticky HTML Element</h1>

<div id="sticky_element">Sticky Element</div>

<div id="content">
  <h2>Lorem ipsum dolor sit amet.</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vel vitae quae eos modi, magni nemo vero dolores sequi corporis minima libero, voluptatum tenetur eveniet molestias illo aut officia laborum facere illum. Porro voluptatum tempore commodi provident magni, accusantium. Sequi, quam!</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Provident accusamus neque beatae odit, cupiditate totam dolor eos odio cumque ipsa nemo quaerat sapiente minima aliquid ipsum libero, explicabo veritatis! Earum explicabo vel ab architecto, incidunt, dicta, voluptatibus iure, tempora ea perspiciatis provident! Veritatis veniam quis distinctio eligendi sunt debitis nam, dolorem facilis, necessitatibus omnis corporis quisquam ad autem quo suscipit repudiandae explicabo illum reiciendis enim atque excepturi. Aspernatur nam maxime odio laborum officia reprehenderit, et blanditiis praesentium fugit alias, illo quod animi consectetur ducimus sapiente sequi. Culpa quae doloribus dolore inventore assumenda perspiciatis, neque dicta provident, sit, saepe voluptate! Neque modi cum, doloremque molestias libero voluptatibus recusandae optio autem nisi culpa ipsa placeat perferendis sed tempore nulla natus amet quas saepe, dolor vitae rem. Et totam eius perspiciatis minima rem ipsam! Quia doloribus cum soluta quae, alias error ratione molestias.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et molestiae ducimus totam cumque repudiandae facere, ex magni odio pariatur sequi id officiis maiores? In, sunt! Veritatis suscipit tempore cupiditate eligendi saepe illo velit. Deleniti ratione ea sequi mollitia, blanditiis at nisi vel, voluptates voluptate fugiat atque repellendus eum. Fuga velit unde qui eligendi quam ipsa quibusdam a laborum ducimus et!</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quas nihil odio fugiat ratione quasi adipisci, minima nemo provident quia nesciunt aperiam saepe quidem sequi neque voluptas. Ab numquam, obcaecati magnam eos, doloribus laborum. Voluptatum dolorem nostrum tempore libero doloremque mollitia recusandae quis alias possimus quisquam! Velit, ut temporibus voluptatibus amet assumenda. Provident laborum dolor repudiandae modi quam ratione et laudantium ad repellendus, rem eligendi illo expedita. Cumque dolor eos beatae voluptatibus, omnis rem velit. Consequatur deserunt enim provident, dolores blanditiis qui voluptatibus, quisquam pariatur sint non reiciendis sunt quidem sed neque repellendus iure. Ad, iure laudantium laborum at fuga maxime facilis neque. Fugiat non temporibus blanditiis in tenetur vitae totam, a soluta laudantium sapiente nihil nesciunt, ipsum, velit! Adipisci, perferendis.</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Modi eius suscipit commodi, nemo natus dolorem impedit blanditiis. Distinctio, similique, voluptatum!</p>
</div>
            
          
!
            
              html, body{
	margin:0px;
	padding:0px;
	font-family: Helvetica, Arial;
}

h1{
	padding:100px 0px;
	margin:0px;
	background:#4527A0;
	color: #fff;
	text-align:center;
}

#content{
	max-width:580px;
	margin:100px auto;
}

#sticky_element{
	width:100%;
	padding:20px 0px;
	background:#7C4DFF;
	color: #fff;
	text-align:center;
	position:absolute;
}

#sticky_element.sticky{
	position:fixed;
	top:0px;
}
            
          
!
            
              $('document').ready(function(){
			var stickyElement = $('#sticky_element');
			var stickyTop = stickyElement.offset().top;

			setSticky();

			$(window).scroll(function(){
				setSticky();
			});

			function setSticky(){
				var winTop = $(window).scrollTop();
				if(winTop >= stickyTop){
					stickyElement.addClass('sticky');
				} else {
					stickyElement.removeClass('sticky');
				}
			}
	});
            
          
!
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.
Loading ..................

Console