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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

HTML

              
                <div id="root">
  <h1>Infinite Scroll with Intersection Observer API</h1>
  <p>Try to scroll me!</p>
  <div id="list"></div>
  <div id="list-end"></div>
</div>

              
            
!

CSS

              
                * {
  font-family: Helvetica, Arial, sans-serif;
  text-align: center;
}

#root {
  background: black;
  overflow: scroll;
  height: 500px;
}

h1 {
  color: darkorange;
}

p {
  color: white;
}

article {
  width: 300px;
  margin: 32px auto;
  background: lightgray;
  border-radius: 6px;
  padding: 16px;
}
              
            
!

JS

              
                // Elements
const root = document.querySelector('#root');
const list = document.querySelector('#list');
const listEnd = document.querySelector('#list-end');

// Render article
let articleCount = 0;
const appendArticle = () => {
  const article = document.createElement('article');
  const textNode = document.createTextNode(`Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
`);
  article.appendChild(textNode);
  list.appendChild(article);
  articleCount++;
};

// Utility to load articles
const loadArticles = () => {
  for (let i = 0; i < 3; ++i) {
    appendArticle();
  }
};

// Interception Handler
const callback = (entries, observer) => {
  for (const entry of entries) {
    console.log(entry);
    // Load more articles;
    if (entry.isIntersecting) {
      if (articleCount < 10) {
        loadArticles();        
      } else {
        observer.unobserve(listEnd);
      }
    }
  }
}

// Observe the end of the list
const observer = new IntersectionObserver(callback, {
  threshold: 0,
});
observer.observe(listEnd);

// Initial loads
loadArticles();
              
            
!
999px

Console