js+svg实现万圣节幽灵般南瓜头文字输入框效果代码
代码语言:html
所属分类:表单美化
代码描述:js+svg实现万圣节幽灵般南瓜头文字输入框效果代码,在输入框中输入文字,就会弹出南瓜头,继续输入,发现文字在南瓜头的嘴里显示出来。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> /* background pattern from heropatterns.com */ @import url("https://fonts.googleapis.com/css2?family=Titan+One&display=swap"); @font-face { font-family: "Stranger"; src: url("//repo.bfw.wiki/bfwrepo/font/StrangerbackintheNight.woff2") format("woff2"); } body, html { height: 100%; display: grid; } body { height: 100vh; width: 100vw; overflow: hidden; } body:before { content: ""; position: absolute; width: 100%; height: 100%; left: 0; top: 0; backdrop-filter: invert(1) saturate(0); z-index: 1; } .gourd { position: absolute; width: 500px; height: 200px; background: rgba(0, 0, 0, 0.5); border-radius: 5px; box-shadow: inset 0 0 0 rgba(0, 0, 0, 0), inset 0 0 0 rgba(0, 0, 0, 0), 0 0 0 1px #eca43a, 0 20px 40px -20px rgba(0, 0, 0, 0.25); left: calc(50% - 250px); top: 50%; transform: translateY(calc(-50% - 25px)); transform-origin: bottom; transition: all 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275); transition-delay: 0.25s; will-change: transform, box-shadow, height, border-radius; transform-style: preserve-3d; border-radius: 10px; z-index: 2; } .gourd:after { content: ""; position: absolute; width: 100px; height: 50px; background: linear-gradient(-25deg, #7baa50, #7baa50 45%, #6f9948 50%, #88b460 55%); border-radius: 100px 0 100px 0; left: 265px; top: -75px; transition: 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275); transform-origin: 0% 100%; transform: scale(0, 0.5); } .gourd:before { content: ""; position: absolute; width: 60px; height: 120px; background: radial-gradient(ellipse at center, #628840 30px, #88b460 30px) 50% 0%/60px 30px no-repeat, #88b460; box-shadow: inset -5px 0 20px #628840, inset 5px 0 20px #628840, 0 5px 40px rgba(0, 0, 0, 0.25); border-radius: 100px/50px; top: -100px; left: calc(50% - 30px); transition: 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275); height: 120px; transform: scaleY(0); transform-origin: bottom; } .gourd .eye { position: absolute; left: 100px; top: 80px; height: 50px; width: 80px; border-radius: 150px 150px 0 0/200px 200px 0 0; background: #241703; box-shadow: inset 0 5px 0 5px #98600f; transition: 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275); transform-origin: bottom; transform: scaleY(0); } .gourd .eye:before { content: ""; position: absolute; width: 30px; height: 17.5px; background: #eca43a; bottom: 0; left: calc((50% - 50px) + (var(--char-total) * 7.5px)); box-shadow: calc(10px - (var(--char-total) * 2px)) -1px 0 1px #af6f11; border-radius: 50px 50px 0 0; transition: transform 400ms cubic-bezier(0.175, 0.885, 0.32, 1.275), left 0.25s ease-in-out, box-shadow 0.25s ease-in-out; transform-origin: bottom; transform: scaleY(0); } .gourd .eye:last-of-type { left: auto; right: 100px; } svg { position: absolute; z-index: 9; width: 400px; height: 400px; left: calc(50% - 200px); top: calc(50% - 187.5px); } svg path { transition: 0.2s ease-in-out; } svg path.mouth1, svg path.mouth2 { stroke: #eca43a; stroke-width: 0px; } svg path.mouth2 { stroke: #0c0801; stroke-width: 4px; } svg foreignObject .pumpkin h1 span.word span.char { transform: translateY(150%); transition: 0.2s ease-in-out; } svg foreignObject .pumpkin h1:first-of-type span.word span.char { transform: translateY(-150%); } svg.open ~ .gourd { background: #eca43a; box-shadow: inset 0 10px 60px rgba(0, 0, 0, 0.5), inset 0 -40px 60px rgba(0, 0, 0, 0.75), 0 0 0 0px #eca43a, 0 20px 40px -20px rgba(0, 0, 0, 0), inset 28px 0 5px #eca43a, inset 37px 0 2px rgba(0, 0, 0, 0.1), inset 72px 0 5px #eca43a, inset 78px 0 2px rgba(0, 0, 0, 0.05), inset -28px 0 5px #eca43a, inset -37px 0 2px rgba(0, 0, 0, 0.1), inset -72px 0 5px #eca43a, inset -78px 0 2px rgba(0, 0, 0, 0.05); border-radius: 200px 200px 300px 300px/250px 250px 300px 300px; height: 400px; transform: translateY(-50%); transition-delay: 0s; } svg.open ~ .gourd:after { transform: scale(1, 1); transition-delay: 0.8s; } svg.open ~ .gourd:before { transform: scaleY(1) skewY(10deg) rotate(-10deg); transition-delay: 0.5s; } svg.open ~ .gourd .eye { transform: scaleY(1); transition-delay: 0.75s; } svg.open ~ .gourd .eye:before { transform: scaleY(1); transition-delay: 1s, 0s, 0s; } svg.open ~ .terrible-text label { background-position: 50% 0%; transition: 0.5s ease-in-out, background-position 0.35s ease-in-out; transform: translateY(-200px); filter: blur(14px); opacity: 0; transition-delay: 0.05s, 0s; } svg.open ~ .terrible-text input { opacity: 0; color: #fff; transition: 0s ease-in-out; } svg.open path { d: path("M 60 300 Q 400 390 740 300 Q 740 340 720 400 C 640 650 180 650 80 400 C 60 340 60 300 60 300 "); } svg.open path.mouth1 { stroke-width: 40px; } svg.open path.mouth2 { fill: transparent; stroke: #98600f; stroke-width: 70px; } svg.open foreignObject#candle { background: #000; } svg.open foreignObject .candle { transition: 3s ease-in-out; transition-delay: 1s; opacity: 1; transform: scale(0.75) translateY(0px); } svg.open foreignObject .pumpkin h1 span.word span.char { animation: toothin 0.5s ease-in-out 1 forwards; } svg.open foreignObject .pumpkin h1 span.word span.char:before { opacity: 0; animation: toothin 0.5s ease-in-out 1 forwards 0.25s; } @keyframes toothin { to { opacity: 1; transform: translateY(0%); } } .pumpkin { opacity: 1; pointer-events: none; position: relative; width: 400px; height: 400px; left: 50%; top: calc(50% + 40px); transform: translate(-50%, -50%) scale(2.05, 1.9); box-shadow: 0 0 0 25px #eca43a; } h1 { font-family: "Titan One"; text-transform: uppercase; text-align: center; margin: 0px; color: #eca43a; transform: scale(0.65) translateY(65px); } h1 .word { font-size: clamp(10px, calc(4px * (20 - var(--char-total))), 80px); } h1:nth-of-type(2) { transform: scale(0.75) translateY(85px); } h1:nth-of-type(2) .word { transform: translateY(calc((1px * var(--char-total)) - 15px)); font-size: clamp(10px, calc(2.5px * (30 - var(--char-total))), 80px); } h1:nth-of-type(2) .word .char { offset-path: path("M 20 174 Q 200 340 374 185 "); } h1:nth-of-type(2) .word .char:before { top: -5px; transform-origin: bottom; } h1 .word { display: block; position: relative; } h1 .word#lower .char:nth-of-type(1) { offset-distance: calc(11.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(2) { offset-distance: calc(23% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(3) { offset-distance: calc(34.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(4) { offset-distance: calc(46% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(5) { offset-distance: calc(57.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(6) { offset-distance: calc(69% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(7) { offset-distance: calc(80.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(8) { offset-distance: calc(92% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(9) { offset-distance: calc(103.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(10) { offset-distance: calc(115% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(11) { offset-distance: calc(126.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(12) { offset-distance: calc(138% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(13) { offset-distance: calc(149.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(14) { offset-distance: calc(161% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(15) { offset-distance: calc(172.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(16) { offset-distance: calc(184% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(17) { offset-distance: calc(195.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(18) { offset-distance: calc(207% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(19) { offset-distance: calc(218.5% - (var(--char-total) * 1%) - 1.5%); } h1 .word#lower .char:nth-of-type(20) { offset-distance: calc(230% - (var(--char-total) * 1%) - 1.5%); } h1 .word .char { position: absolute; left: 0; top: 0; offset-path: path("M 0 170 Q 200 220 400 170 "); } h1 .word .char:nth-of-type(1) { offset-distance: calc(13% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(2) { offset-distance: calc(26% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(3) { offset-distance: calc(39% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(4) { offset-distance: calc(52% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(5) { offset-distance: calc(65% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(6) { offset-distance: calc(78% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(7) { offset-distance: calc(91% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(8) { offset-distance: calc(104% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(9) { offset-distance: calc(117% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(10) { offset-distance: calc(130% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(11) { offset-distance: calc(143% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(12) { offset-distance: calc(156% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(13) { offset-distance: calc(169% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(14) { offset-distance: calc(182% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(15) { offset-distance: calc(195% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(16) { offset-distance: calc(208% - (var(--char-total) * 1%) - 2%); } h1 .word .char:nth-of-type(17) { offset-distance: calc(221% - (var(--char.........完整代码请登录后点击上方下载按钮下载查看
网友评论0