Skip to content

Commit 6a90994

Browse files
committed
chore: update to gsap3
1 parent 0614e8c commit 6a90994

File tree

2 files changed

+60
-61
lines changed

2 files changed

+60
-61
lines changed

093-creative portfolio/index.html

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,7 @@ <h3>03</h3>
197197
</aside>
198198
</main>
199199
</div>
200-
<script
201-
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TweenMax.min.js"
202-
integrity="sha256-lPE3wjN2a7ABWHbGz7+MKBJaykyzqCbU96BJWjio86U="
203-
crossorigin="anonymous"
204-
></script>
205-
<script
206-
src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.1.3/TimelineMax.min.js"
207-
integrity="sha256-fIkQKQryItPqpaWZbtwG25Jp2p5ujqo/NwJrfqAB+Qk="
208-
crossorigin="anonymous"
209-
></script>
200+
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.13.0/gsap.min.js"></script>
210201
<script src="script.js"></script>
211202
</body>
212203
</html>

093-creative portfolio/script.js

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,26 @@ function init() {
99
];
1010
let current = 0;
1111
let scrollSlide = 0;
12+
let isAnimating = false;
13+
14+
function updateActiveDot(index) {
15+
slides.forEach((slide) => slide.classList.remove("active"));
16+
slides[index].classList.add("active");
17+
}
1218

1319
slides.forEach((slide, index) => {
1420
slide.addEventListener("click", function () {
15-
changeDots(this);
21+
if (isAnimating) return;
22+
updateActiveDot(index);
1623
nextSlide(index);
1724
scrollSlide = index;
1825
});
1926
});
2027

21-
function changeDots(dot) {
22-
slides.forEach((slide) => slide.classList.remove("active"));
23-
dot.classList.add("active");
24-
}
28+
async function nextSlide(pageNumber) {
29+
if (isAnimating || pageNumber === current) return;
30+
isAnimating = true;
2531

26-
function nextSlide(pageNumber) {
2732
const nextPage = pages[pageNumber];
2833
const currentPage = pages[current];
2934
const nextLeft = nextPage.querySelector(".hero .model-left");
@@ -33,81 +38,84 @@ function init() {
3338
const nextText = nextPage.querySelector(".details");
3439
const portfolio = document.querySelector(".portfolio");
3540

36-
const tl = new TimelineMax({
37-
// disable clicks during animations
38-
onStart: function () {
39-
slides.forEach((slide) => (slide.style.pointerEvents = "none"));
40-
},
41-
onComplete: function () {
42-
slides.forEach((slide) => (slide.style.pointerEvents = "all"));
43-
},
44-
});
45-
46-
tl.fromTo(currentLeft, 0.3, { y: "-10%" }, { y: "-100%" })
47-
.fromTo(currentRight, 0.3, { y: "10%" }, { y: "-100%" }, "-=0.2")
48-
.to(portfolio, 0.3, { backgroundImage: backgrounds[pageNumber] })
41+
const tl = gsap.timeline({});
42+
tl.fromTo(currentLeft, { y: "-10%" }, { duration: 0.3, y: "-100%" })
43+
.fromTo(
44+
currentRight,
45+
{ y: "10%" },
46+
{ duration: 0.3, y: "-100%" },
47+
"-=0.2"
48+
)
49+
.to(portfolio, {
50+
duration: 0.3,
51+
backgroundImage: backgrounds[pageNumber],
52+
})
4953
.fromTo(
5054
currentPage,
51-
0.3,
52-
{ opacity: 1, pointerEvents: "all" },
53-
{ opacity: 0, pointerEvents: "none" }
55+
{ opacity: 1 },
56+
{ duration: 0.3, opacity: 0, pointerEvents: "none" }
5457
)
5558
.fromTo(
5659
nextPage,
57-
0.3,
5860
{ opacity: 0, pointerEvents: "none" },
59-
{ opacity: 1, pointerEvents: "all" },
61+
{ duration: 0.3, opacity: 1, pointerEvents: "all" },
6062
"-=0.6"
6163
)
62-
.fromTo(nextLeft, 0.3, { y: "-100%" }, { y: "-10%" }, "-=0.6")
63-
.fromTo(nextRight, 0.3, { y: "-100%" }, { y: "10%" }, "-=0.8")
64-
.fromTo(nextText, 0.3, { opacity: 0, y: 0 }, { opacity: 1, y: 0 })
64+
.fromTo(nextLeft, { y: "-100%" }, { duration: 0.3, y: "-10%" }, "-=0.6")
65+
.fromTo(nextRight, { y: "-100%" }, { duration: 0.3, y: "10%" }, "-=0.8")
66+
.fromTo(nextText, { opacity: 0, y: 0 }, { duration: 0.3, opacity: 1 })
6567
.set(nextLeft, { clearProps: "all" })
6668
.set(nextRight, { clearProps: "all" });
69+
70+
await tl;
71+
6772
current = pageNumber;
73+
isAnimating = false;
6874
}
6975
document.addEventListener("wheel", throttle(scrollChange, 1500));
70-
document.addEventListener("touchmove", throttle(scrollChange, 1500));
71-
72-
function swithDots(dotNumber) {
73-
const activeDot = document.querySelectorAll(".slide")[dotNumber];
74-
slides.forEach((slide) => slide.classList.remove("active"));
75-
activeDot.classList.add("active");
76-
}
7776

7877
function scrollChange(e) {
78+
if (isAnimating) return;
7979
e.deltaY > 0 ? (scrollSlide += 1) : (scrollSlide -= 1);
80-
// reset
8180
if (scrollSlide > 2) scrollSlide = 0;
8281
if (scrollSlide < 0) scrollSlide = 2;
83-
swithDots(scrollSlide);
82+
updateActiveDot(scrollSlide);
8483
nextSlide(scrollSlide);
8584
}
8685

8786
// menu
8887
const hamburger = document.querySelector(".menu");
89-
const hamburgerLines = document.querySelectorAll(".menu line");
90-
const navOpen = document.querySelector(".nav-open");
91-
const contact = document.querySelector(".contact");
92-
const social = document.querySelector(".social");
93-
const logo = document.querySelector(".logo");
94-
95-
const tl = new TimelineMax({ paused: true, reversed: true });
9688

97-
tl.to(navOpen, 0.5, { y: 0 })
98-
.fromTo(contact, 0.5, { opacity: 0, y: 10 }, { opacity: 1, y: 0 }, "-=0.1")
99-
.fromTo(social, 0.5, { opacity: 0, y: 10 }, { opacity: 1, y: 0 }, "-=0.5")
100-
.fromTo(logo, 0.2, { color: "var(--white)" }, { color: "black" }, "-=1")
89+
const menuTl = gsap.timeline({ paused: true, reversed: true });
90+
menuTl
91+
.to(".nav-open", { duration: 0.5, y: 0 })
92+
.fromTo(
93+
".contact",
94+
{ opacity: 0, y: 10 },
95+
{ duration: 0.5, opacity: 1, y: 0 },
96+
"-=0.1"
97+
)
98+
.fromTo(
99+
".social",
100+
{ opacity: 0, y: 10 },
101+
{ duration: 0.5, opacity: 1, y: 0 },
102+
"-=0.5"
103+
)
104+
.fromTo(
105+
".logo",
106+
{ color: "var(--white)" },
107+
{ duration: 0.2, color: "black" },
108+
"-=1"
109+
)
101110
.fromTo(
102-
hamburgerLines,
103-
0.2,
111+
".menu line",
104112
{ stroke: "var(--white)" },
105-
{ stroke: "black" },
113+
{ duration: 0.2, stroke: "black" },
106114
"-=1"
107115
);
108116

109117
hamburger.addEventListener("click", () => {
110-
tl.reversed() ? tl.play() : tl.reverse();
118+
menuTl.reversed() ? menuTl.play() : menuTl.reverse();
111119
});
112120
}
113121

0 commit comments

Comments
 (0)