論壇

通知
清除所有

[已解決] 代碼顯示

2 posts
2 users
0 Reactions
56 views
李維
職位: 12
管理員
Topic starter
(@feng)
會員
Joined: 1 週 前
<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,
          開始: "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 動畫 = 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,
          開始: "top 120%",
          end: "top 60%",
          動畫: 動畫,
          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,
          開始: "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>
主題標籤
1 Reply
裏克
職位: 1
(@rick)
New Member
Joined: 1 週 前

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

Reply
分享:

返回頁首按鈕