gsap+ScrollTrigger实现可调节参数的横向图片相册立体弧形滚动效果代码
代码语言:html
所属分类:加载滚动
代码描述:gsap+ScrollTrigger实现可调节参数的横向图片相册立体弧形滚动效果代码,通过tweakpane可修改参数,实现不同的排列效果。
代码标签: gsap ScrollTrigger 调节 参数 横向 图片 相册 立体 弧形 滚动
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0, maximum-scale=1.0" /> <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/normalize.5.0.css"> <style> @import "normalize.css"; html { color-scheme: light only; } [data-dark="true"] { color-scheme: dark only; } *, *:after, *:before { box-sizing: border-box; } body { display: grid; place-items: center; min-height: 100svh; font-family: "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui; overflow: hidden; } body::before { --size: 60px; --line: color-mix(in lch, canvasText 35%, hsl(0 0% 100% / 0.25)); content: ''; height: 100svh; width: 100vw; position: fixed; background: linear-gradient( 90deg, var(--line) 1px, transparent 1px var(--size) ) 50% 50% / var(--size) var(--size), linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% / var(--size) var(--size); -webkit-mask: linear-gradient(-25deg, transparent 65%, white); mask: linear-gradient(-25deg, transparent 65%, white); top: 0; transform-style: flat; pointer-events: none; z-index: -1; } main { transform-style: preserve-3d; position: relative; transition: scale 0.2s; height: 100svh; display: grid; place-items: center; width: 100%; } .container { --scroll-padding: 0px; --inner-angle: calc((360 / var(--total)) * 1deg); --item-width: clamp(120px, 20vmin, 12rem); --scroll-buff: calc(var(--item-width) * var(--scroll-ratio)); --gap: calc(var(--item-width) * var(--gap-efficient, 0.1)); --radius: calc(((var(--item-width) + var(--gap)) / sin(var(--inner-angle))) * -1); position: relative; width: 100%; height: 100%; overflow: auto; timeline-scope: --controller; } [data-infinite="true"] .container { --scroll-padding: calc(var(--item-width) * 0.01); --scroll-padding: 5px; } ul { list-style-type: none; padding: 0; margin: 0; display: grid; } img { border-radius: 12px; width: 100%; height: 100%; background-color: color-mix(in lch, canvasText 25%, canvas); } h1 { position: fixed; bottom: 1rem; right: 1rem; color: color-mix(in lch, canvasText, transparent); opacity: 0; transition: opacity 0.2s; } [data-scroll=true] h1 { opacity: 1; } .carousel { padding: 0; } .carousel { display: flex; } .carousel { width: 100%; height: 100%; position: absolute; left: 50%; top: 50%; translate: -50% -50%; } .carousel-container { height: 100%; width: 100%; -webkit-mask: linear-gradient( calc(90deg + (var(--rotate-z) * 1deg)), transparent 0 calc(50% - (var(--item-width) * var(--mask-upper))), white calc(50% - (var(--mask-lower) * var(--item-width))) calc(50% + (var(--mask-lower) * var(--item-width))), transparent calc(50% + (var(--mask-upper) * var(--item-width))) 100% ); mask: linear-gradient( calc(90deg + (var(--rotate-z) * 1deg)), transparent 0 calc(50% - (var(--item-width) * var(--mask-upper))), white calc(50% - (var(--mask-lower) * var(--item-width))) calc(50% + (var(--mask-lower) * var(--item-width))), transparent calc(50% + (var(--mask-upper) * var(--item-width))) 100% ); pointer-events: none; position: absolute; display: grid; place-items: center; inset: 0; transform-style: preserve-3d; perspective: calc(var(--perspective) * 1px); overflow: hidden; } [data-scroll="true"] .carousel::after, [data-animate="true"] .carousel::after { -webkit-animation: shine calc(var(--total) * 0.5s) infinite linear; animation: shine calc(var(--total) * 0.5s) infinite linear; } [data-scroll="true"] .carousel, [data-animate="true"] .carousel { -webkit-animation: carousel calc(var(--total) * 0.5s) infinite linear; animation: carousel calc(var(--total) * 0.5s) infinite linear; } .carousel { transform-style: preserve-3d; transform: translate3d(0, 0, var(--radius)) rotateX(calc(var(--rotate-x) * 1deg)) rotateZ(calc(var(--rotate-z) * 1deg)) rotateY(0deg); } @-webkit-keyframes carousel { to { transform: translate3d(0, 0, var(--radius)) rotateX(calc(var(--rotate-x) * 1deg)) rotateZ(calc(var(--rotate-z) * 1deg)) rotateY(-360deg); } } @keyframes carousel { to { transform: translate3d(0, 0, var(--radius)) rotateX(calc(var(--rotate-x) * 1deg)) rotateZ(calc(var(--rotate-z) * 1deg)) rotateY(-360deg); } } @supports(animation-timeline: scroll()) { [data-scroll="true"] .carousel, [data-scroll="true"] .carousel::after { -webkit-animation-duration: auto; animation-duration: auto; -webkit-animation-iteration-count: 1; animation-iteration-count: 1; -webkit-animation-fill-mode: both; animation-fill-mode: both; animation-timeline: --controller; } } .carousel::after { content: ""; position: absolute; top: 50%; left: 50%; width: calc(var(--item-width) * 1.5); height: calc(var(--item-width) * 1.5); -webkit-backdrop-filter: brightness(2); backdrop-filter: brightness(2); -webkit-mask: radial-gradient(80% 80% at 50% 50%, white, transparent 50%); mask: radial-gradient(80% 80% at 50% 50%, white, transparent 50%); transform: translate(-50%, -50%) rotateY(0deg) translate3d(0, 0, calc((var(--radius) - 10px) * -1)); } @-webkit-keyframes shine { to { transform: translate(-50%, -50%) rotateY(360deg) translate3d(0, 0, calc((var(--radius) - 10px) * -1)); } } @keyframes shine { to { transform: translate(-50%, -50%) rotateY(360deg) translate3d(0, 0, calc((var(--radius) - 10px) * -1)); } } [data-gsap="true"] .carousel::after { -webkit-animation: none; animation: none; transform: translate(-50%, -50%) rotateY(calc(var(--rotate) * 1deg)) translate3d(0, 0, calc((var(--radius) - 10px) * -1)); } .carousel li { --debug: red; height: var(--item-width); width: var(--item-width); outline-offset: 2px; } .carousel li { position: absolute; top: 50%; left: 50%; -webkit-backface-visibility: hidden; backface-visibility: hidden; transform: translate(-50%, -50%) rotateY(calc((var(--inner-angle) * var(--index)))) translate3d(0, 0, calc(var(--radius) * -1)); } [data-backface="true"] .carousel li { -webkit-backface-visibility: visible; backface-visibility: visible; } .controller { display: flex; overflow: auto; width: 100%; height: 100%; -ms-scroll-snap-type: x mandatory; scroll-snap-type: x mandatory; scroll-timeline: --controller inline; align-items: center; padding-inline: calc((50vw + var(--scroll-padding)) - (var(--scroll-buff) * 0.5)); } [data-vertical="true"] .controller { flex-direction: column; -ms-scroll-snap-type: y mandatory; scroll-snap-type: y mandatory; scroll-timeline: --controller; padding-inline: 0; padding-block: calc((50svh + var(--scroll-padding)) - (var(--scroll-buff) * 0.5)); } .controller li { --debug: red; height: var(--scroll-buff); width: var(--scroll-buff); aspect-ratio: 1; flex: 1 0 auto; scroll-snap-align: center; } [data-debug="true"] li { outline: 2px dashed var(--debug); } /*.carousel { animation: carousel both linear; animation-timeline: --controller; animation-range: var(--scroll-padding) calc(100% - var(--scroll-padding)); }*/ /*.carousel li { filter: saturate(0.75) brightness(0.75); }*/ div.tp-lblv_v { flex-shrink: 1; width: auto; } div.tp-dfwv { width: 300px; } .bear-link { color: canvasText; position: fixed; bottom: 1rem; left: 1rem; width: 48px; aspect-ratio: 1; display: grid; place-items: center; opacity: 0.8; } :where(.x-link, .bear-link):is(:hover, :focus-visible) { opacity: 1; } .bear-lin.........完整代码请登录后点击上方下载按钮下载查看
网友评论0