<section>
<img
class="logo"
width="40" src="https://cdn.worldvectorlogo.com/logos/gsap-greensock.svg" />
</section>
<section>
<img
class="logo"
width="40" src="https://cdn.worldvectorlogo.com/logos/gsap-greensock.svg" />
</section>
<section> <img
class="logo"
width="40" src="https://cdn.worldvectorlogo.com/logos/gsap-greensock.svg" /></section>
<section> <img
class="logo"
width="40" src="https://cdn.worldvectorlogo.com/logos/gsap-greensock.svg" /></section>
* {
padding: 0;
margin: 0;
}
section {
height: 100vh;
display: flex;
justify-content: start;
algin-item: center
position: relative;
}
section:nth-child(1) {
background: lightblue;
}
section:nth-child(1)::after {
content: '直接播放';
position: absolute;
opacity: .2;
z-index: 1;
}
section:nth-child(1)::before {
content: 'A';
position: absolute;
font-size: 80px;
opacity: .2;
height: 100vh;
display: flex;
align-items: center;
z-index: 1;
}
section:nth-child(2) {
background: lightgreen;
}
section:nth-child(2)::after {
content: '向下進入(播放) / 向下離開 (暫停) / 向上進入 (恢復播放) / 向上離開 (倒轉)';
position: absolute;
opacity: .2;
z-index: 1;
}
section:nth-child(2)::before {
content: 'B';
position: absolute;
font-size: 80px;
opacity: .2;
height: 100vh;
display: flex;
align-items: center;
z-index: 1;
}
section:nth-child(3) {
background: pink;
}
section:nth-child(3)::after {
content: '進入區塊後,依滾動 播放與倒轉';
position: absolute;
opacity: .2;
z-index: 1;
}
section:nth-child(3)::before {
content: 'C';
position: absolute;
font-size: 80px;
opacity: .2;
height: 100vh;
display: flex;
align-items: center;
z-index: 1;
}
section:nth-child(4) {
background: orange;
}
section:nth-child(4)::after {
content: '進入區塊,才觸發 (播放)';
position: absolute;
opacity: .2;
z-index: 1;
}
section:nth-child(4)::before {
content: 'D';
position: absolute;
font-size: 80px;
opacity: .2;
height: 100vh;
display: flex;
align-items: center;
z-index: 1;
}
img {
z-index: 2;
}
const logo = document.querySelectorAll('.logo')
const a = logo[0]
const b = logo[1]
const c = logo[2]
const d = logo[3]
const sectionA = 'section:nth-child(1)'
const sectionB = 'section:nth-child(2)'
const sectionC = 'section:nth-child(3)'
const sectionD = 'section:nth-child(4)'
gsap.to(a, {
duration: 5,
xPercent: 1000,
rotation: 360
})
gsap.to(b, {
scrollTrigger: {
trigger: sectionB,
toggleActions: 'play pause resume reverse',
},
duration: 5,
xPercent: 1000,
rotation: 360
})
gsap.to(c, {
scrollTrigger: {
trigger: sectionC,
scrub: true, // 依滾動 播放/倒帶 (druation 將無效)
},
xPercent: 1000,
rotation: 360
})
gsap.to(d, {
scrollTrigger: sectionD,
duration: 3,
xPercent: 1000,
rotation: 360
})
This Pen doesn't use any external CSS resources.