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

              
                <div class="box box1">1</div>
<div class="box box2">2</div>
<div class="box box3">3</div>
              
            
!

CSS

              
                .box {
 height: 400px;
 text-align: center;
 font-size: 50px;
 color: white;
 line-height: 400px;
}

.box1 {
 background-color: greenyellow;
}

.box2 {
 background-color: blueviolet;
}

.box3 {
 background-color: pink;
}
              
            
!

JS

              
                // const isElementVisible = (el) => {
//  const rect = el.getBoundingClientRect();
//  const vWidth = window.innerWidth || document.documentElement.clientWidth;
//  const vHeight = window.innerHeight || document.documentElement.clientHeight;

//  if (
//   rect.right < 0 ||
//   rect.bottom < 0 ||
//   rect.left > vWidth ||
//   rect.top > vHeight
//  ) {
//   return false;
//  }
 
 
//  return true
// };

// function checkBoxVisible() {
//  const box1 = document.querySelector(".box1");
//  console.log("box1 is visible: ", isElementVisible(box1));

//  const box2 = document.querySelector(".box2");
//  console.log("box2 is visible: ", isElementVisible(box2));

//  const box3 = document.querySelector(".box3");
//  console.log("box3 is visible: ", isElementVisible(box3));
// }

// checkBoxVisible();
// window.addEventListener("scroll", (_) => {
//  checkBoxVisible();
// });

const boxes = document.querySelectorAll('.box')

const observer = new IntersectionObserver((entries, observer) => {
 entries.forEach((entry) => {
    console.log(
      entry.target,
      entry.isIntersecting ? "visible" : "invisible"
    );
  });
})

boxes.forEach((box) => {
  observer.observe(box);
});
              
            
!
999px

Console