gsap+ScrollTrigger实现全屏图文滚动式幻灯片效果代码

代码语言:html

所属分类:幻灯片

代码描述:gsap+ScrollTrigger实现全屏图文滚动式幻灯片效果代码

代码标签: gsap ScrollTrigger 全屏 图文 滚动式 幻灯片 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
 
<meta charset="UTF-8">
 

 
 
<style>
@font-face {
    font-family: "Geist Sans";
    src: url("https://assets.codepen.io/605876/GeistVF.ttf") format("truetype");
  }

*,
*:after,
*:before {
        box-sizing: border-box;
}

html {
        -ms-scroll-snap-type: y mandatory;
            scroll-snap-type: y mandatory;
}

body {
        min-height: 100vh;
        font-family:  "Geist Sans", "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui;
        font-weight: 80;
        background: black;
        color: hsl(0 0% 90%);
        overflow-x: hidden;
}

p {
        max-width: 40ch;
}

section:nth-of-type(1) {
        scroll-snap-align: center;
        height: 100vh;
}

section:nth-of-type(2) {
        scroll-snap-align: start;
}

article {
        min-height: 100vh;
}
:is(h1, h2) {
        font-weight: 70;
        font-size: clamp(2.5rem, 3.35vw + 1rem, 8rem);
        letter-spacing: -0.075ch;
        margin: 0;
}

h1 {
        color: hsl(0 0% 90%);
}

:is(section, article) {
        position: relative;
}

nav {
        position: fixed;
        top: 0;
        width: 100%;
        padding: 1rem;
        z-index: 999;
        display: flex;
        justify-content: space-between;
}
nav a:first-of-type {
        width: 48px;
        aspect-ratio: 1;
        display: grid;
        place-items: center;
        color: white;
}
nav a:last-of-type {
        background: hsl(173 100% 51%);
        color: black;
        padding: 1rem 2rem;
        border-radius: 22px;
        text-decoration: none;
        font-weight: 120;
        transition: background 0.2s;
}
nav a:last-of-type:is(:hover, :focus-visible) {
        background: hsl(173 100% 40%);
}

.content {
        margin: 0 auto;
        width: 900px;
        max-width: 100%;
        height: 100%;
        z-index: 2;
        position: absolute;
        inset: 0;
  padding: 1rem;
}

.fixed img {
        height: 100%;
        width: 150%;
        -o-object-fit: cover;
           object-fit: cover;
        z-index: -1;
        position: absolute;
        inset: 0;
        left: 50%;
        translate: -50% 0;
        filter: brightness(0.5);
}

section:first-of-type img {
        left: 50%;
        translate: -50% 0;
}

section:first-of-type {
        padding: 2rem 1rem;
        display: grid;
        align-content: end;
        justify-content: start;
}

section:first-of-type .fixed {
        z-index: 5;
}

section:first-of-type .fixed .content {
        margin: 0 auto;
        width: 900px;
        max-width: 100%;
        display: grid;
        align-content: center;
        justify-content: start;
        padding: 6rem 2rem;
        height: 100%;
}

section:first-of-type {
        background: black;
}

section:first-of-type p {
        font-size: clamp(1rem, 0.2vw + 1rem, 2rem);
        padding: 0 2rem 0 0;
}

section:nth-of-type(2) article:first-of-type .fixed {
        z-index: 2;
}

section:nth-of-type(2) .content {
        display: grid;
        padding: 4rem 1rem;
        align-content: center;
}

section:nth-of-type(2) article:first-of-type .content {
        align-content: end;
}

section:nth-of-type(2) article:first-of-type .fixed::after {
        content: "";
        position: absolute;
        inset: 0;
        background: hsl(0 0% 0% / 0.25);
}

section:nth-of-type(2) article:first-of-type h2 {
        padding: 1rem 0;
}

section:nth-of-type(2) article:nth-of-type(2) h2 {
        padding: 0 2rem 0 0;
}

section:nth-of-type(2) article:nth-of-type(2) .fixed {
        background: black;
        z-index: 2;
}

section:nth-of-type(2) article:nth-of-type(3) .content {
        align-content: start;
}

section:nth-of-type(2) article:nth-of-type(3) .fixed {
        z-index: 2;
}

section:nth-of-type(2) article:nth-of-type(3) img {
        filter: saturate(0.5) brightness(0.5);
}

.text-blocks {
        width: 100%;
        max-width: 46ch;
        justify-self: end;
        display: grid;
        place-items: center;
        gap: 2rem 0;
        padding-right: 2rem;
}

/* Text block styling */
.chat-container {
        height: 100vh;
        width: 100%;
        position: sticky;
        top: 0;
        display: grid;
        place-items: center;
}
.text-blocks p {
        display: inline-block;
        border-radius: 6px;
        margin: 0;
        font-size: clamp(1.5rem, 0.5vw + 1rem, 4rem);
        font-weight: 120;
}
.text-blocks p:nth-of-type(even) {
        justify-self: end;
        text-align: right;
        color: hsl(173 100% 51%);
}
.text-blocks p:nth-of-type(odd) {
        justify-self: start;
}

.filler {
        display: none;
}

/* Scroll indicators */
.indicators {
        width: 20px;
        aspect-ratio: 1 / 7;
        position: fixed;
        top: 50%;
        right: 1rem;
        z-index: 999999;
        translate: 0 -50%;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0