Pen Settings



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


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="wrapper">
    <div id="targetImage" class="image"></div>
    <p id="targetTitle" class="title">Hello World!</p>
    <p id="targetCaption" class="caption">
      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.


                body {
  font-family: -apple-system, BlinkMacSystemFont, Hiragino Sans, '游ゴシック体', YuGothic, 'Yu Gothic Medium', Meiryo, sans-serif;

.wrapper {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 800px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  > .image {
    display: block;
    width: 400px;
    height: 400px;
    margin-bottom: 24px;
    background: url('');
    background-size: cover;
  > .title {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 16px;
  > .caption {
    font-size: 18px;
    text-align: center;
    line-height: 1.6;
    color: gray;


  duration: 0.1,
  ease: 'none'

class TargetProps {
  constructor(target) {
    this.el = target
    this.y = target.offsetTop
    this.height = target.clientHeight = this.y - window.innerHeight
    this.bottom = this.y + this.height

window.addEventListener('load', () => {
  const image = new TargetProps(document.getElementById('targetImage'))
  const title = new TargetProps(document.getElementById('targetTitle'))
  const caption = new TargetProps(document.getElementById('targetCaption'))
  let scrollAmount = window.pageYOffset
  let isRafActive = false
  function calculateRatio(top, bottom, scroll) {
    const topAdjustNum = top * ((bottom - scroll) / bottom)
    return (bottom - scroll + topAdjustNum) / bottom

  function updatePosition(target, ratio, distance) {
    if (0 < ratio && ratio < 1) {, {
        y: distance - distance * ratio

  const ratio = {
    image: calculateRatio(, image.bottom, scrollAmount),
    title: calculateRatio(, title.bottom, scrollAmount),
    caption: calculateRatio(, caption.bottom, scrollAmount),

  // Set target position when page load
  updatePosition(image.el, ratio.image, 200)
  updatePosition(title.el, ratio.title, -320)
  updatePosition(caption.el, ratio.caption, 40)

  window.addEventListener('scroll', throttle(16, () => {
    scrollAmount = window.pageYOffset
    ratio.image = calculateRatio(, image.bottom, scrollAmount)
    ratio.title = calculateRatio(, title.bottom, scrollAmount)
    ratio.caption = calculateRatio(, caption.bottom, scrollAmount)

    if (!isRafActive) {
      isRafActive = true
      requestAnimationFrame(() => {
        updatePosition(image.el, ratio.image, 200)
        updatePosition(title.el, ratio.title, -320)
        updatePosition(caption.el, ratio.caption, 40)
        isRafActive = false
  }), {passive: true})