Animation gsap fade in
GSAP + ScrollTrigger(CDN)。画面内に入ると下からフェードイン。
2023年12月以降、すべてのブラウザーで利用可能です。
- Baseline
- BaselineWidely available
- 対応ブラウザ
- Chrome120+Edge120+Firefox117+Safari17.2+
プレビューを読み込み中
<div class="animation-gsap-fade-in js-animation-gsap-fade-in">
<div class="animation-gsap-fade-in__intro">
<div class="animation-gsap-fade-in__scroll-hint">
<p class="animation-gsap-fade-in__hint">
スクロールすると要素がフェードインします
</p>
<span class="animation-gsap-fade-in__arrow" aria-hidden="true">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<path
d="M4 6l4 4 4-4"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</span>
</div>
</div>
<div class="animation-gsap-fade-in__list">
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-01.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-02.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-03.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-04.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
</div>
</div>
<script src="https://unpkg.com/gsap@3.15.0/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3.15.0/dist/ScrollTrigger.min.js"></script>
<div class="animation-gsap-fade-in js-animation-gsap-fade-in">
<div class="animation-gsap-fade-in__intro">
<div class="animation-gsap-fade-in__scroll-hint">
<p class="animation-gsap-fade-in__hint">
スクロールすると要素がフェードインします
</p>
<span class="animation-gsap-fade-in__arrow" aria-hidden="true">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<path
d="M4 6l4 4 4-4"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</span>
</div>
</div>
<div class="animation-gsap-fade-in__list">
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-01.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-02.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-03.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
<figure class="animation-gsap-fade-in__item">
<img
class="animation-gsap-fade-in__image"
src="/snippets/card-sample-04.jpg"
alt=""
width="640"
height="360"
decoding="async"
/>
</figure>
</div>
</div>
<script src="https://unpkg.com/gsap@3.15.0/dist/gsap.min.js"></script>
<script src="https://unpkg.com/gsap@3.15.0/dist/ScrollTrigger.min.js"></script>
/* reset */
:where(.animation-gsap-fade-in) {
box-sizing: border-box;
}
:where(p).animation-gsap-fade-in__hint,
:where(figure).animation-gsap-fade-in__item {
margin: 0;
}
:where(img).animation-gsap-fade-in__image {
display: block;
}
/* snippet */
.animation-gsap-fade-in {
--animation-background: #fff;
--animation-hint-color: #5e6775;
width: 100%;
background-color: var(--animation-background);
}
.animation-gsap-fade-in__intro {
display: grid;
place-items: center;
min-height: 400px;
padding: 24px;
}
.animation-gsap-fade-in__scroll-hint {
display: grid;
row-gap: 8px;
justify-items: center;
color: var(--animation-hint-color);
}
.animation-gsap-fade-in__hint {
font-size: 14px;
line-height: 1.6;
text-align: center;
}
.animation-gsap-fade-in__arrow {
display: grid;
animation: animation-gsap-fade-in-bounce 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
.animation-gsap-fade-in__arrow {
animation: none;
}
}
@keyframes animation-gsap-fade-in-bounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(4px);
}
}
.animation-gsap-fade-in__list {
display: grid;
row-gap: 64px;
width: 100%;
padding-block: 48px 80px;
}
.animation-gsap-fade-in__item {
width: min(72%, 480px);
overflow: hidden;
border-radius: 8px;
}
.animation-gsap-fade-in__item:nth-child(odd) {
justify-self: start;
}
.animation-gsap-fade-in__item:nth-child(even) {
justify-self: end;
}
.animation-gsap-fade-in__image {
width: 100%;
height: auto;
}
/* reset */
:where(.animation-gsap-fade-in) {
box-sizing: border-box;
}
:where(p).animation-gsap-fade-in__hint,
:where(figure).animation-gsap-fade-in__item {
margin: 0;
}
:where(img).animation-gsap-fade-in__image {
display: block;
}
/* snippet */
.animation-gsap-fade-in {
--animation-background: #fff;
--animation-hint-color: #5e6775;
width: 100%;
background-color: var(--animation-background);
}
.animation-gsap-fade-in__intro {
display: grid;
place-items: center;
min-height: 400px;
padding: 24px;
}
.animation-gsap-fade-in__scroll-hint {
display: grid;
row-gap: 8px;
justify-items: center;
color: var(--animation-hint-color);
}
.animation-gsap-fade-in__hint {
font-size: 14px;
line-height: 1.6;
text-align: center;
}
.animation-gsap-fade-in__arrow {
display: grid;
animation: animation-gsap-fade-in-bounce 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
.animation-gsap-fade-in__arrow {
animation: none;
}
}
@keyframes animation-gsap-fade-in-bounce {
0%,
100% {
transform: translateY(0);
}
50% {
transform: translateY(4px);
}
}
.animation-gsap-fade-in__list {
display: grid;
row-gap: 64px;
width: 100%;
padding-block: 48px 80px;
}
.animation-gsap-fade-in__item {
width: min(72%, 480px);
overflow: hidden;
border-radius: 8px;
}
.animation-gsap-fade-in__item:nth-child(odd) {
justify-self: start;
}
.animation-gsap-fade-in__item:nth-child(even) {
justify-self: end;
}
.animation-gsap-fade-in__image {
width: 100%;
height: auto;
}
(function () {
function getScroller(root) {
const overflowY = getComputedStyle(root).overflowY;
return overflowY === "auto" || overflowY === "scroll"
? root
: document.documentElement;
}
function init() {
if (typeof gsap === "undefined" || typeof ScrollTrigger === "undefined") {
return;
}
gsap.registerPlugin(ScrollTrigger);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
document.querySelectorAll(".js-animation-gsap-fade-in").forEach((root) => {
if (root.dataset.animationGsapFadeInInit) return;
root.dataset.animationGsapFadeInInit = "true";
const items = root.querySelectorAll(".animation-gsap-fade-in__item");
if (!items.length) return;
if (reducedMotion) return;
const scroller = getScroller(root);
let nextAt = 0;
items.forEach((item) => {
gsap.set(item, { opacity: 0, y: 40 });
ScrollTrigger.create({
trigger: item,
scroller,
start: "top 80%",
once: true,
onEnter: () => {
const now = performance.now() / 1000;
const delay = Math.max(0, nextAt - now);
nextAt = now + delay + 0.18;
gsap.to(item, {
opacity: 1,
y: 0,
duration: 0.7,
delay,
ease: "power2.out",
});
},
});
});
ScrollTrigger.refresh();
});
}
if (typeof gsap !== "undefined" && typeof ScrollTrigger !== "undefined") {
init();
return;
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init, { once: true });
} else {
init();
}
})();
(function () {
function getScroller(root) {
const overflowY = getComputedStyle(root).overflowY;
return overflowY === "auto" || overflowY === "scroll"
? root
: document.documentElement;
}
function init() {
if (typeof gsap === "undefined" || typeof ScrollTrigger === "undefined") {
return;
}
gsap.registerPlugin(ScrollTrigger);
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)",
).matches;
document.querySelectorAll(".js-animation-gsap-fade-in").forEach((root) => {
if (root.dataset.animationGsapFadeInInit) return;
root.dataset.animationGsapFadeInInit = "true";
const items = root.querySelectorAll(".animation-gsap-fade-in__item");
if (!items.length) return;
if (reducedMotion) return;
const scroller = getScroller(root);
let nextAt = 0;
items.forEach((item) => {
gsap.set(item, { opacity: 0, y: 40 });
ScrollTrigger.create({
trigger: item,
scroller,
start: "top 80%",
once: true,
onEnter: () => {
const now = performance.now() / 1000;
const delay = Math.max(0, nextAt - now);
nextAt = now + delay + 0.18;
gsap.to(item, {
opacity: 1,
y: 0,
duration: 0.7,
delay,
ease: "power2.out",
});
},
});
});
ScrollTrigger.refresh();
});
}
if (typeof gsap !== "undefined" && typeof ScrollTrigger !== "undefined") {
init();
return;
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init, { once: true });
} else {
init();
}
})();