Pen Settings



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


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


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.


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.


                <div class="mainBox">
  <h3>Intersection Observer Example</h3>
  <p>Visible area / view port
    When target box intersect with this view by 30%, 50% and 80% color of the target box changes to red, blue and green respectively.
  <div class="targetBox"></div>


                .mainBox {
  border: 1px solid black;
  width: 500px;
  height: 400px;
  margin: 0 auto;
  overflow-y: scroll;
  text-align: center;

.targetBox {
  width: 300px;
  height: 100px;
  border: 1px solid #ccc;
  background: #ccc;
  margin: 50px auto;
  margin-top: 500px; 
  color: #fff;
  padding: 10px;


                if(!("IntersectionObserver" in window)) {
  document.body.innerText = "Not supported by your browser";
window.addEventListener("load", function(event) {
  const mainBox = document.querySelector(".mainBox");
  /* Creating observer */
  const options = {
    root: mainBox,
    rootMargin: '0px',
    threshold: [0.3, 0.5, 0.8, 1]
  const observer = new IntersectionObserver(handler, options);
  /* Defining target object */
  const target = document.querySelector(".targetBox");
}, false);

/* Defining callback handler */
function handler(entries, observer) {
   console.log("Observer handler called: ");
    entries.forEach(entry => {
      const intersectionRatio = entry.intersectionRatio.toFixed(2);
     = "Interserction ratio: " + intersectionRatio;
      if (intersectionRatio > 0.8) { = "green";
      } else if(intersectionRatio > 0.5) { = "blue";
      } else if(intersectionRatio > 0.2) { = "red";