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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

HTML

              
                <div id='root'></div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.sectionContainer {
  width: 100%;
  height: calc(100vh - 80px);
  margin-top: 80px;
  background-color: pink;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card {
  background: rgba(14, 7, 38);
  border: 1.5px solid rgba(140, 320, 75);
  border-radius: 20px;
  padding: 40px 20px;
  color: white;
  width: 500px;
  height: 300px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.cardHeader {
  margin-bottom: 15px;
}

  .cardsContainer {
    width: 100%;
    height: 100%;
    position: relative;
  }


.content-filler {
  background-color: lightblue;
  width: 100%;
  height: 2000px;
}

              
            
!

JS

              
                const App = () => {
  
  return (
    <>
      <CardsComponent />
    </>
  )
}

const CardsComponent = () => {
  const { useState, useEffect} = React;
  const [rotation, setRotation] = useState(0);
  
  const data = [
  {
    title: 'Lorem1',
    description:
      'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown text ever since the 1500s, when an unknown',
  },
  {
    title: 'Lorem2',
    description:
      'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown ',
  },
  {
    title: 'Lorem3',
    description:
      'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown ',

  },
];
  
  useEffect(() => {
    gsap.registerPlugin(ScrollTrigger);

    const cards = gsap.utils.toArray('.card');
    const sectionContainer = document.querySelector('.sectionContainer');

    const scrollDistance = 1000;

//     const scrolling = {
//       enable: true,
//       events: 'scrolling, wheel, touchmove, pointermove'.split(','),
//       prevent: (e) => e.preventDefault(),
//       disable() {
//         if (scrolling.enable) {
//           scrolling.enable = false;
//           window.addEventListener('scroll', gsap.ticker.tick, { passive: true });
//           scrolling.events.forEach((e, index) =>
//             (index ? document : window).addEventListener(e, scrolling.prevent, { passive: false }),
//           );
//         }
//       },
//       enable() {
//         if (!scrolling.enable) {
//           scrolling.enable = true;
//           window.removeEventListener('scroll', gsap.ticker.tick);
//           scrolling.events.forEach((e, index) =>
//             (index ? document : window).removeEventListener(e, scrolling.prevent),
//           );
//         }
//       },
//     };

//     cards.forEach((card, index) => {
//       if (index > 0) {
//         gsap.set(card, { opacity: 0, x: 100 });
//       }
//     });

//     const tl = gsap.timeline();

//     const scrollAnimation = (card, index) => {
//       if (scrolling.enable) {
//         scrolling.disable();

//         if (index > 0) {
//           tl.to(card, { opacity: 1, x: 0 });
//         }

//         if (index < cards.length - 1) {
//           tl.to(card, { x: -100, opacity: 0 });
//         }
//       }
//     };

//     cards.forEach((card, index) => {
//       ScrollTrigger.create({
//         trigger: sectionContainer,
//         pin: sectionContainer,
//         pinSpacing: true,
//         start: 'top top+=80',
//         end: `bottom+=${scrollDistance}`,
//         markers: true,
//         onUpdate: (self) => {
//           setRotation(self.progress * 360);
//         },
//         onToggle: (self) => self.isActive && !tl && scrollAnimation(card, index),
//       });
//     });

    // const goToPosition = (card, anim, index) => {
    //   if (scrolling.enable) {
    //     scrolling.disable();
    //     gsap.to(window, {
    //       scrollTo: { y: card, autokill: false },
    //       onComplete: scrolling.enable,
    //     });
    //     anim && anim.restart();
    //   }
    // };

    // cards.forEach((card, index) => {
    //   const intoAnim = gsap.timeline();
    //   if (index > 0) {
    //     gsap.set(card, { opacity: 0, x: 100 });

    //     intoAnim.to(card, { opacity: 1, x: 0 });
    //   }

    //   if (index < card.length - 1) {
    //     intoAnim.to(card, { x: -100, opacity: 0 });
    //   }

    //   ScrollTrigger.create({
    //     trigger: sectionContainer,
    //     pinSpacing: true,
    //     start: 'top top+=80',
    //     end: `bottom+=${scrollDistance}`,
    //     markers: true,
    //     onUpdate: (self) => {
    //       setRotation(self.progress * 360);
    //     },
    //     onEnter: () => goToPosition(card, intoAnim),
    //     onEnterBack: () => goToPosition(card),
    //   });
    // });

    // create invisible elements that we'll put into the DOM for the sole purpose of serving as scroll snapping positions
    const snapElements = cards.map(card => {
      let el = document.createElement("div");
      gsap.set(el, {visibility: "hidden", position: "absolute", scrollSnapAlign: "start", top: 0});
      document.body.appendChild(el);
      return el;
    })
    
    const tl = gsap.timeline({
      scrollTrigger: {
        trigger: sectionContainer,
        pin: sectionContainer,
        pinSpacing: true,
        scrub: true,
        start: 'top top+=80',
        end: `bottom+=${scrollDistance}`,
        markers: true,
        onToggle: self => document.scrollingElement.style.scrollSnapType = self.isActive ? "y mandatory" : "none",
        onRefresh: (self) => {
          // set up all the scroll snapping positions
          snapElements.forEach((el, i) => gsap.set(el, {y: self.start + (self.end - self.start) / (snapElements.length - 1 - i)}));
        },
        onUpdate: (self) => {
          setRotation(self.progress * 360);
        },
      },
    });

    cards.forEach((card, index) => {
      if (index > 0) {
        gsap.set(card, { opacity: 0, x: 100 });

        tl.to(card, { opacity: 1, x: 0 });
      }

      if (index < cards.length - 1) {
        tl.to(card, { x: -100, opacity: 0 });
      }
    });
  }, []);
  
  return (
    <>
        <div className='sectionContainer'>
          <div className='cardsContainer'>
            {data.map((card, index) => (
              <div className={'card'} key={`card${index}`}>
                <div className='cardHeader'>
                  <h2>
                    {card.title}
                  </h2>
                </div>
                <div className='cardContent'>
                  <h5>
                    {card.description}
                  </h5>
                </div>
              </div>
            ))}
        </div>
    </div>
    <section className="content-filler"></section>
      </>
  )
}

ReactDOM.render(<App />, document.querySelector('#root'));
              
            
!
999px

Console