Lauro235 / horizontalScroll

Check out my vanilla JS horizonal scrolling web project.

Home Page:https://lauro235.github.io/horizontalScroll/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

horizontalScroll

Purpose of project

In this project I learnt how to make a horizontal scrolling website.

See the project

Resources

Method

  1. Create a flex wrapper with height and width of 100vh/vw
  2. Create nested div with the following CSS values
  • display: flex;
  • width: 100vw;
  • flex-shrink: 0; Flex will set all inner contents side by side horizontally. 100vw will ensure that the contents of the div take up all screen width flex-shrink: 0; ensures that each child component individually takes up full screen width (individual children are not shrunk so that all children are within the screen, rather overflow takes place)
  1. Place some content in the nested div...
  2. Finally let's add the js. We will
  • Target the wrapper element
  • add a scroll event listener
    wrapper.addEventListener('wheel', transformScroll);
  1. Pass in call back
  • prevent default bevhaviour
  • leverage scrollTo()
  • pass in options
    {
      top: 0,
      left: wrapper.scrollLeft += e.deltaY,
      behavior: 'smooth',
    }

You will notice that the value of wrapper.scrollLeft + window.innerWidth is equal to wrapper.scrollWidth.

scrollLeft takes you as far as it can go, but scrollWidth includes the innerWidth to. It takes you to the end of all content.

About

Check out my vanilla JS horizonal scrolling web project.

https://lauro235.github.io/horizontalScroll/


Languages

Language:HTML 47.2%Language:CSS 43.4%Language:JavaScript 9.5%