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.

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">
  <div id="target"></div>
</div>

<div id="output">intersectionRatio: <pre></pre></div>

<div id="buttons">
  <button id="center">center</button>
  <button id="left">left</button>
  <button id="top">top</button>
  <button id="corner">corner</button>
  <button id="large">large</button>
</div>
            
          
!

CSS

            
              html {
  box-sizing: border-box;
  font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
}
*, *:before, *:after {
  box-sizing: inherit;
}
html,
body {
  background-color: #1d1e22;
  margin: 0;
  padding: 0;
}

#root {
  align-items: center;
  background-color: #FFF;
  border: 3px solid rebeccapurple;
  display: flex;
  height: 400px;
  justify-content: center;
  margin: 20px auto;
  overflow: visible;
  position: relative;
  width: 400px;
}

#target {
  background-color: rebeccapurple;
  background-image: radial-gradient(ellipse at center, #ffffff 0%,#ffffff 14%,#663399 15%,#663399 34%,#ffffff 35%,#ffffff 50%,#663399 51%,#663399 99%);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 300px 300px;
  height: 300px;
  pointer-events: none;
  transition: 0.5s;
  width: 300px;
}
#target.left {
  opacity: 0.5;
  transform: translate3d(-200px, 0, 0);
}
#target.top {
  opacity: 0.5;
  transform: translate3d(0, -200px, 0);
}
#target.corner {
  opacity: 0.5;
  transform: translate3d(200px, -200px, 0);
}
#target.large {
  height: 500px;
  opacity: 0.5;
}

#output {
  color: #FFF;
  margin: 20px auto;
  width: 400px;
}
#output pre {
  display: inline;
  font-size: 16px;
  padding: 0 10px;
}

#buttons {
  display: flex;
  justify-content: space-around;
  margin: 20px auto;
  position: relative;
  width: 400px;
  z-index: 2;
}
#buttons button {
  background-color: #FFF;
  border: 3px solid rebeccapurple;
  color: rebeccapurple;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  padding: 0.5rem 1rem;
  transition: 0.25s 0.25s;
}
            
          
!

JS

            
              const root = document.querySelector('#root');
const target = document.querySelector('#target');
const output = document.querySelector('#output pre');
const io_options = {
  root: root,
  rootMargin: '0px',
  threshold: [...Array(100).keys()].map(x => x / 100)
};
let io_observer;

function io_callback (entries) {
  output.innerText = entries[0].intersectionRatio;
}

function clickHandler (e) {
  target.setAttribute('class', e.target.id);
}

document.querySelectorAll('#buttons button').forEach(function (btn) {
  btn.addEventListener('click', clickHandler);
});

io_observer = new IntersectionObserver(io_callback, io_options);
io_observer.observe(target);
            
          
!
999px

Console