Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <header>
  <h1>Lepljivi naslov</h1>
</header>

<section>
  <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Dicta ipsum ipsam sapiente dolores quibusdam assumenda illum totam vitae consequatur, natus omnis culpa blanditiis reiciendis fugit laboriosam. Nostrum repudiandae ducimus deserunt!</div>
  <div>Cupiditate voluptate impedit sequi porro, commodi aperiam ratione vitae similique voluptas dicta perspiciatis quisquam hic ducimus nulla quam exercitationem odit rerum. Aut autem facere corporis tenetur possimus maiores adipisci nulla!</div>
  <div>Voluptatum maxime labore nulla, corporis maiores, facere qui numquam sapiente ipsum voluptatibus magnam! A, vel id nobis cupiditate ut corrupti, odio similique nulla maxime amet autem enim? Labore, vel sit!</div>
  <div>Laborum illo ab repudiandae quis voluptates praesentium magni non obcaecati quibusdam, sequi, a doloremque nemo eligendi sapiente. Omnis, ad? Eveniet debitis recusandae sequi est id magni, cum doloribus minima ratione.</div>
  <div>Officiis nisi, ab vel cumque amet voluptatem rem ducimus quaerat in unde, et, obcaecati officia vero at nam expedita ea aspernatur id cupiditate dolore corporis? Doloribus ipsum exercitationem quae rerum?</div>
 <div>Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus ea, necessitatibus cupiditate exercitationem distinctio sint expedita quos quibusdam soluta nisi sed? Ut aliquid eaque expedita alias quos laboriosam natus illum!</div>
 <div>Tenetur aspernatur totam modi, quaerat consequatur, aperiam veritatis at esse officiis, enim consequuntur hic earum incidunt voluptate quis fugit facere ex corrupti! Tempore sequi harum a blanditiis obcaecati. Quod, nemo!</div>
 <div>Sunt reiciendis neque distinctio animi, maxime sed minus, atque natus eum saepe, fuga ut et at repellendus cupiditate deserunt perferendis iure rem voluptate commodi ipsum mollitia ullam debitis. Iusto, ex?</div>
 <div>Consequuntur dicta architecto doloremque harum nostrum exercitationem repellendus quasi dolorem quis quidem, adipisci neque quam inventore nihil nobis labore in dolore ad excepturi quia officiis impedit accusantium eos. Sint, ullam.</div>
 <div>Unde beatae, iste ipsam mollitia quibusdam, magnam aut tenetur quam possimus laborum rem, adipisci culpa quia saepe facilis laboriosam natus. Saepe voluptate placeat ratione at, velit eligendi aspernatur ipsum nam.</div>
</section>
              
            
!

CSS

              
                header {
  height: 200px;
  text-align: center;
  background: black;
}

h1 {
  margin: 0;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  color: white;

  &.fix {
    margin: 0;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    line-height: 1.5;
    transform: translateY(0);
    background: black;
  }
}
              
            
!

JS

              
                var header = document.querySelector('header');
var naslov = header.querySelector('h1');
var visinaHeadera = getComputedStyle(header).height.split('px')[0];
var visinaNaslova = getComputedStyle(naslov).height.split('px')[0];
var rastojanjeOdNaslovaDoVrhaHeadera= ((visinaHeadera - visinaNaslova) / 2);

window.addEventListener('scroll', function (e) {
  var velicinaScrolla = window.scrollY;
  if( velicinaScrolla > rastojanjeOdNaslovaDoVrhaHeadera) {
    naslov.classList.add("fix");
  }
  if( velicinaScrolla < rastojanjeOdNaslovaDoVrhaHeadera) {
    naslov.classList.remove("fix");
  }
}, false);
              
            
!
999px

Console