Vertical image sweep

Vertical image sweep comparison – GSAP/Scrolltrigger/CSS/Bootstrap5

HTML

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello, world!</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="main.css">
  </head>
  <body>
    <div class="head fixed-top">
        <div class="container-fluid bg-primary">
            <nav class="navbar navbar-expand-lg navbar-dark">
                <div class="container-fluid">
                  <a class="navbar-brand" href="#"><img src="images/symbol.svg" height="24px"> <span class="fw-bold">Meeny</span>.com</a>
                  <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                  </button>
                  <div class="collapse navbar-collapse" id="navbarNavDropdown">
                    <ul class="navbar-nav ms-auto">
                      <li class="nav-item">
                        <a class="nav-link active" aria-current="page" href="#">Home</a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link" href="#">Features</a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link" href="#">Pricing</a>
                      </li>
                      <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                          Dropdown link
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                          <li><a class="dropdown-item" href="#">Action</a></li>
                          <li><a class="dropdown-item" href="#">Another action</a></li>
                          <li><a class="dropdown-item" href="#">Something else here</a></li>
                        </ul>
                      </li>
                    </ul>
                  </div>
                </div>
              </nav>
        </div>
        <span class="progressBar"></span>
    </div>
   

<div class="Mwrap">
  <div class="panel pn1 bg-primary">Base</div>
  <div class="panel pn2 bg-secondary">ONE</div>
  <div class="panel pn3 bg-success">TWO</div>
  <div class="panel pn4 bg-info">THREE</div>
  <div class="panel pn5 bg-warning">FOUR</div>

  <div class="mmain text-center bg-primary h-100 row">
    <div class="my-auto">
      <h3>GSAP ScrollTrigger</h3>
    </div>
  </div>

</div>



        
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/gsap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.6.0/ScrollTrigger.min.js"></script>
    <script src="main.js"></script>

  </body>
</html>

SCSS

@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600;700&display=swap');
@import url("https://fonts.googleapis.com/css?family=Noto+Sans+KR:100,300,400,500,700,900&display=swap&subset=korean");
$font-family-base: 'Oswald', sans-serif;


$primary:       #fca311 !default;
$secondary:     #1d3557 !default;
$success:       #457b9d !default;
$info:          #a8dadc !default;
// $warning:       #f1faee !default;
// $danger:        $red !default;
// $light:         $gray-100 !default;
// $dark:          $gray-900 !default;


@import "./node_modules/bootstrap/scss/bootstrap";

html, body, .Mwrap, .panel{
    height: 100%;
}

body{
    overflow-x: hidden;
    overflow-y: scroll;
}

.Mwrap{
    width: 100% !important;
    //display: flex;
    //flex-wrap: nowrap;
}

.panel{
    width: 100%;
    font-weight: 700;
    font-size: 1.5em;
    color: $white;
    display: flex;
    justify-content: center;
    align-items: center;

    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    background-attachment: fixed;


    &:nth-child(2) {
        background-image: url(images/m1.jpg);
    }
    &:nth-child(3) {
        background-image: url(images/m2.jpg);
    }
    &:nth-child(4) {
        background-image: url(images/m3.jpg);
    }
    &:nth-child(5) {
        background-image: url(images/m4.jpg);
    }

}




.progressBar{
    width: 100%;
    height: 4px;
    position: relative;
    display: inline-block;
    background-color: rgba(255,255,255,.8);

}

JS

gsap.registerPlugin(ScrollTrigger);

// let sections = gsap.utils.toArray(".panel");

// gsap.to(sections, {
//   xPercent: -100 * (sections.length - 1),
//   ease: "none",
//   scrollTrigger: {
//     trigger: ".Mwrap",
//     pin: true,
//     scrub: 1,
//     snap: 1 / (sections.length - 1),
//     // base vertical scrolling on how wide the container is so it feels more natural.
//     end: () => "+=" + document.querySelector(".Mwrap").offsetWidth
//   }
// });

gsap.to(".pn5",{
  scrollTrigger:{
    trigger: ".mmain",
    scrub:true,
    toggleActions: "restart pause reverse pause"
  },
  backgroundAttachment: "local",
  duration:1

})


gsap.from(".progressBar",{
  scrollTrigger:{
    trigger:".pn1",
    scrub: true,
    start: "top top",
    end:()=> document.querySelector(".Mwrap").offsetHeight * 5
  },
  scaleX: 0,
  transformOrigin: "left center",
  ease: "none"

});

답글 남기기

이메일 주소를 발행하지 않을 것입니다. 필수 항목은 *(으)로 표시합니다