Forum

Notifications
Retirer tout

[Résolu] code show

2 posts
2 users
0 Reactions
57 views
Levi
Postes: 12
 Levi
Administrateur
Début du sujet
(@feng)
Membre
Inscription: Il y a 1 semaine
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.0/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.0/ScrollTrigger.min.js"></script>

<script>
let mediaAnimation = gsap.matchMedia();
ScrollTrigger.defaults({
  markers: false
});

const colors = ["#2E4D71", "#856546", "#05625C", "#5A483E", "#886648"];

mediaAnimation.add("(min-width: 666px)", () => {
  // Desktop animations
  const details = gsap.utils.toArray(".desktopContentSection:not(:first-child)");
  const photos = gsap.utils.toArray(".desktopPhoto:not(:first-child)");

  gsap.set(photos, { clipPath: 'inset(100% 0% 0% 0%)', autoAlpha: 1 });

  const allPhotos = gsap.utils.toArray(".desktopPhoto");

  details.forEach((section, i) => {
      let bgColor = colors[i + 1];
      ScrollTrigger.create({
          trigger: section,
          commencer: "200 bottom",
          end: "+=100%",

          onToggle: self => {
              if (self.isActive) {
                  gsap.à(".gallery", { backgroundColor: bgColor });
              } else if ((i === 0 && self.direction < 0) || (i === details.length - 1 && self.direction > 0)) {
                  gsap.à(".gallery", { backgroundColor: "#2E4D71" });
              }
          }
      });
  });

  details.forEach((detail, index) => {
      let headline = detail.querySelector(".reveal");
      let animation = gsap.timeline()
          .à(photos[index], { clipPath: 'inset(0% 0% 0% 0%)', autoAlpha: 1, duration: 1.5 })
          .set(allPhotos[index], { autoAlpha: 1, duration: 1.5 });

      ScrollTrigger.create({
          trigger: headline,
          commencer: "top 120%",
          end: "top 60%",
          animation: animation,
          scrub: true,
          markers: false
      });
  });
});

mediaAnimation.add("(max-width: 665px)", () => {
  // Mobile animations
  const details = gsap.utils.toArray(".desktopContentSection:not(:first-child)");

  details.forEach((section, i) => {
      let bgColor = colors[i + 1];
      ScrollTrigger.create({
          trigger: section,
          commencer: "200 bottom",
          end: "+=100%",

          onToggle: self => {
              if (self.isActive) {
                  gsap.à(".gallery", { backgroundColor: bgColor });
              } else if ((i === 0 && self.direction < 0) || (i === details.length - 1 && self.direction > 0)) {
                  gsap.à(".gallery", { backgroundColor: "#2E4D71" });
              }
          }
      });
  });
});
</script>
Étiquettes du sujet
1 Réponse
Rick
Postes: 1
 Rick
(@rick)
New Member
Inscription: Il y a 1 semaine

I tried it out; it would be even better if I could use an animated GIF, like this one

Répondre
Partager:

Bouton retour en haut de la page