gsap ScrollTrigger实现滚动翻书动画效果
代码语言:html
所属分类:动画
代码描述:gsap ScrollTrigger实现滚动翻书动画效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> * { box-sizing: border-box; } :root { --page-count: 20; --page-scroll: 25; --underline: rgba(64,64,64,0.4); --spine: #000; --cover: #1a1a1a; --bg: #4d4d4d; --insert: #d9d9d9; --page: #e6e6e6; } body { width: 100vw; height: calc(((var(--page-count) + 2) * var(--page-scroll)) * 1vh); background: var(--bg); overflow-x: hidden; } h1 { text-align: center; font-size: 1rem; margin: 0; padding: 0; } .page { height: 100%; width: 100%; position: relative; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; } .page .page__number { position: absolute; color: #808080; bottom: 1rem; font-size: 1vmin; } .page__half--front .page__number { right: 1rem; } .page__half--back .page__number { left: 1rem; } .page__half { display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; height: 100%; position: absolute; top: 0; left: 0; width: 100%; -webkit-transform: rotateY(calc(var(--rotation) * 1deg)) translate3d(0, 0, calc((0.5 * var(--coefficient)) * 1px)); transform: rotateY(calc(var(--rotation) * 1deg)) translate3d(0, 0, calc((0.5 * var(--coefficient)) * 1px)); -webkit-clip-path: inset(0 0.5% 0 0.5%); clip-path: inset(0 0.5% 0 0.5%); } .page__half--front { --rotation: 0; --coefficient: 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; border-radius: 0 5% 5% 0; } .page__half--back { --rotation: 180; --coefficient: 2; border-radius: 5% 0 0 5%; } .book { height: 40vmin; position: fixed; width: 30vmin; min-width: 150px; min-height: 200px; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%) scale(0.5); transform: translate(-50%, -50%) scale(0.5); -webkit-transform-style: preserve-3d; transform-style: preserve-3d; -webkit-perspective: 1200px; perspective: 1200px; } .book__insert { content: ''; position: absolute; height: 94%; width: 94%; background: var(--insert); top: 50%; right: -1rem; -webkit-transform: translate(0, -50%); transform: translate(0, -50%); border-radius: 5% 0 0 5%; } .book__spine { height: 100%; left: 0; top: 0; position: absolute; background: var(--spine); -webkit-transform-origin: 0 50%; transform-origin: 0 50%; width: 12px; -webkit-transform: translate3d(0, 0, -13px) scaleX(1) rotateY(0deg); transform: translate3d(0, 0, -13px) scaleX(1) rotateY(0deg); } .book__page { position: absolute; left: 2%; top: 50%; border-radius: 0 5% 5% 0; -webkit-transform: translate(0, -50%); transform: translate(0, -50%); height: 94%; width: 94%; z-index: calc(((var(--page-count) + 2) - var(--page-index)) * 2); -webkit-transform-origin: 0% 50%; transform-origin: 0% 50%; } .book__cover { border-radius: 0 5% 5% 0; height: 100%; width: 100%; position: absolute; top: 50%; left: 0; background: var(--cover); } .book__cover--front { -webkit-transform-origin: 0 50%; transform-origin: 0 50%; } .book__cover--front .page__half--back { border-right: 1rem solid var(--spine); } .book__cover--back { -webkit-transform-origin: 0% 50%; transform-origin: 0% 50%; } .book__cover--back .page__half--front { border-left: 1rem solid var(--spine); } .book__cover--back .book__insert { left: 0; border-radius: 0 5% 5% 0; } .book__page:not(.book__cover) .page__half { background: repeating-linear-gradient(0deg, transparent 0 1rem, var(--underline) 1rem calc(1rem + 1px), transparent calc(1rem + 1px)) 0 1rem/100% 100% no-repeat, var(--page); } .sticker { height: 15%; position: absolute; bottom: 5%; right: 5%; -webkit-transform: rotate(-25deg); transform: rotate(-25deg); } .code { line-height: 1.2; font-family: monospace; white-space: pre-line; max-width: 100%; max-height: 100%; font-weight: bold; color: #0f0f0f; text-shadow: 2px 2px 0 #1c1c1c; border-radius: 5%; display: block; overflow: hidden; } .gsap-logo { position: absolute; top: 50%; left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); opacity: 0; height: 50%; } img { width: 90%; height: 90%; -o-object-fit: center; object-fit: center; z-index: 2; } </style> </head> <body translate="no"> <div class="book"> <div class="book__spine"></div> <div class="page book__page book__cover book__cover--front" style="--page-index: 1;"> <div class="page__half page__half--front"><span class="code">set(FOLD,{transformOrigin:"50% 100%",scaleY:0}),set(CLIPS,{transformOrigin:"50% 0"}),set(".cannon__shirt",{opacity:0}),set(".cannon",{y:28}),set(".text--ordered .char",{y:"100%"});const SPEED=.15,FOLD_TL=()=>new timeline().to(LEFT_ARM,{duration:SPEED,rotateY:-180,transformOrigin:`${100*(22/65.3)}% 50%`},0).to(RIGHT_ARM,{duration:SPEED,rotateY:-180,transformOrigin:`${100*((65.3-22)/65.3)}% 50%`},SPEED).to(FOLD,{duration:SPEED/4,scaleY:1},2*SPEED).to(FOLD,{duration:SPEED,y:-47},2*SPEED+.01).to(CLIPS,{duration:SPEED,scaleY:.2},2*SPEED).to(".cannon",{duration:SPEED,y:0},2*SPEED),LOAD_TL=()=>new timeline().to(".button__shirt",{transformOrigin:"50% 13%",rotate:90,duration:.15}).to(".button__shirt",{duration:.15,y:60}).to(".t-shirt__cannon",{y:5,repeat:1,yoyo:!0,duration:.1}).to(".t-shirt__cannon",{y:50,duration:.5,delay:.1}),FIRE_TL=()=>new timeline().set(".t-shirt__cannon",{rotate:48,x:-85,scale:2.5}).set(".cannon__shirt",{opacity:1}).to(".t-shirt__cannon-content",{duration:1,y:-35}).to(".t-shirt__cannon-content",{duration:.25,y:-37.5}).to(".t-shirt__cannon-content",{duration:.015,y:-30.5}).to(".cannon__shirt",{onStart:()=>CLIP.play(),duration:.5,y:"-25vmax"},"<").to(".text--ordered .char",{duration:.15,stagger:.1,y:"0%"}).to("button",{duration:.15*7,"--hue":116,"--lightness":55},"<"),ORDER_TL=new timeline({paused:!0});ORDER_TL.set(".cannon__shirt",{opacity:0}),ORDER_TL.set("button",{"--hue":260,"--lightness":20}),ORDER_TL.to("button",{scale:300/BUTTON.offsetWidth,duration:SPEED}),ORDER_TL.to(".text--order .char",{stagger:.1,y:"100%",duratio.........完整代码请登录后点击上方下载按钮下载查看
网友评论0