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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono&family=IBM+Plex+Sans+JP&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="style.css" />
    <title>hybrid scrolling</title>
  </head>
  <body>
    <main>
      <section>
        <div class="container">
          <h1>Hybrid Scrolling</h1>
          <p>Dummy text dummy text dummy text dummy text dummy text.</p>
        </div>
      </section>

      <div class="scroll_container">
        <div class="sticky_wrap">
          <div class="horizontal_scroll"></div>
        </div>
      </div>

      <section>
        <div class="container">
          <h1>Middle</h1>
          <p>Dummy text dummy text dummy text dummy text dummy text.</p>
        </div>
      </section>

      <div class="scroll_container">
        <div class="sticky_wrap">
          <div class="horizontal_scroll"></div>
        </div>
      </div>

      <section>
        <div class="container">
          <h1>The End</h1>
          <p>Dummy text dummy text dummy text dummy text dummy text.</p>
        </div>
      </section>

    </main>
    <script src="./script.js"></script>
  </body>
</html>

              
            
!

CSS

              
                * {
  margin: 0px;
  padding: 0px;
  font-family: 'IBM Plex Mono';
  box-sizing: border-box;
  scroll-behavior: smooth;
}

html, body, main {
  width: 100%;
  height: 100%;
}

body {
  background-color: #f7f7f7;
  color: #010101;
}

h1 {
  font-size: 2rem;
}

p {
  width: 90%;
  margin: 2rem 0;
}

section {
  height: 100vh;
}

.container {
  padding: 5rem;
}

.scroll_container {
  height: 600vh;
}

.horizontal_scroll {
  position: absolute;
  top: 0;
  height: 100%;
  width: 600vw;
  will-change: transform;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 5vw;
}

.sticky_wrap {
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
}

.red {
  background-color: #ff3d00;
}

.yellow {
  background-color: #ffff00;
}

.green {
  background-color: #05ff00;
}

.blue {
  background-color: #2835f8;
}

h2 {
  font-size: 3rem;
  color: #f7f7f7;
}

.left {
  margin-top: 5vh;
  margin-left: 5vw;
}

.right {
  text-align: right;
  margin-top: 85vh;
  margin-right: 5vw;
}

img {
  width: 200px;
  height: 60%;
  object-fit: cover;
  object-position: center;
}
              
            
!

JS

              
                
// The spread operator will turn all items into an array
const stickySections = [...document.querySelectorAll('.sticky_wrap')]
// console.log(stickySections);

let images = [
  'https://raw.githubusercontent.com/bibomato/hybrid_scroll_img/633269acf63b2ab55e72b69d9402f4c37388ac2d/image/image01.jpg',
  'https://raw.githubusercontent.com/bibomato/hybrid_scroll_img/633269acf63b2ab55e72b69d9402f4c37388ac2d/image/image02.jpg',
  'https://raw.githubusercontent.com/bibomato/hybrid_scroll_img/633269acf63b2ab55e72b69d9402f4c37388ac2d/image/image03.jpg',
  'https://raw.githubusercontent.com/bibomato/hybrid_scroll_img/633269acf63b2ab55e72b69d9402f4c37388ac2d/image/image04.jpg',
  'https://raw.githubusercontent.com/bibomato/hybrid_scroll_img/633269acf63b2ab55e72b69d9402f4c37388ac2d/image/image05.jpg'
]

images.forEach(img => {
  stickySections.forEach(section => {
    let image = document.createElement('img');
    image.src = img;
    section.querySelector('.horizontal_scroll').appendChild(image)
  })
})

window.addEventListener('scroll', (e) => {
  for(let i = 0; i < stickySections.length; i++){
    transform(stickySections[i])
  }
})

function transform(section) {

  // This will get the Y distance from top
  const offsetTop = section.parentElement.offsetTop;
  // console.log(offsetTop);

  // This grabs each scroll section
  const scrollSection = section.querySelector('.horizontal_scroll')

  // This works out the percentage of the screen and converts it to a VW value
  let percentage = ((window.scrollY - offsetTop) / window.innerHeight) * 100;

  // If it is less than 0, don't transform
  // Else if the percentage is greater than 300, remain at 300
  // Else transform
  percentage = percentage < 0 ? 0 : percentage > 500 ? 500 : percentage;
  // Using 400vw as the original class goes too 500vw, but if it goes to the full 500vw it will overflow

  // Viewport height is then converted to the viewport width
  scrollSection.style.transform = `translate3d(${-(percentage)}vw, 0, 0)`
  // You could use translate( vw, 0) here as well
}
              
            
!
999px

Console