d3与spliting实现文字环绕动画效果
代码语言:html
所属分类:动画
代码描述:d3与spliting实现文字环绕动画效果
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css?family=Lato&display=swap"); * { box-sizing: border-box; } body { min-height: 100vh; display: -webkit-box; display: flex; -webkit-box-align: center; align-items: center; -webkit-box-pack: center; justify-content: center; font-family: 'Lato', sans-serif; } .container { height: 40vmin; position: relative; width: 40vmin; width: calc((112.748 / 241.22) * 40vmin); } .char { --delay: calc(((var(--char-total) - var(--char-index))) - var(--word-index)); offset-path: path(var(--path)); -webkit-animation: travel 6s calc((var(--delay) * (0.15)) * -1s) infinite linear both; animation: travel 6s calc((var(--delay) * (0.15)) * -1s) infinite linear both; offset-rotate: auto 180deg; position: absolute !important; font-size: 4vmin; font-weight: bold; top: 0%; left: 0%; -webkit-transform: translate(0, -2.5vmin); transform: translate(0, -2.5vmin); } svg { height: 100%; width: 100%; } path { stroke: #111; stroke-width: 2.5px; fill: rgba(0,64,255,0.25); fill: url("#popsicle-gradient"); } .gradient { height: 0; width: 0; } @-webkit-keyframes travel { from { offset-distance: 0%; } to { offset-distance: 100%; } } @keyframes travel { from { offset-distance: 0%; } to { offset-distance: 100%; } } </style> </head> <body translate="no"> <div class="container"> <svg xmlns="http://www.w3.org/2000/svg" viewbox="0 -2 112.748 246.22"> <lineargradient id="popsicle-gradient" gradientunits="userSpaceOnUse" x1="0%" y1="0%" x2="100%" y2="0%" gradientTransform="rotate(45) scale(2)"> <stop offset="0%" stop-color="hsl(180, 100%, 50%)" stop-opacity="1"></stop> <stop offset="19%" stop-color="hsl(180, 100%, 50%)" stop-opacity="1"></stop> <stop offset="20%" stop-color="hsl(100, 100%, 50%)" stop-opacity="1"></stop> <stop offset="39%" stop-color="hsl(100, 100%, 50%)" stop-opacity="1"></stop> <stop offset="40%" stop-color="hsl(305, 100%, 75%)" stop-opacity="1"></stop> <stop offset="59%" stop-color="hsl(305, 100%, 75%)" stop-opacity="1"></stop> <stop offset="60%" stop-color="hsl(250, 100%, 65%)" stop-opacity="1"></stop> <stop offset="79%" stop-color="hsl(250, 100%, 65%)" stop-opacity="1"></stop> <stop offset="80%" stop-color="hsl(60, 100%, 50%)" stop-opacity="1"></stop> <stop offset="100%" stop-color="hsl(60, 100%, 50%)" stop-opacity="1"></stop> </lineargradient> <path d="M56.374 0C25.143 0 0 23.65 0 53.028v126.43c0 4.793 4.102 8.652 9.198 8.652h35.604v44.654c0 4.684 5.16 8.456 11.571 8.456 6.41 0 11.572-3.772 11.572-8.456V188.11h35.605c5.095 0 9.198-3.86 9.198-8.652V53.028C112.748 23.651 87.605 0 56.374 0z"></path> </svg> <div class="text" data-splitting="">Stay cool...</div> </div> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/d3.js"></script> <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/splitting.min.js"></script> <script > const { d3, Splitting } = window /** * Meanderer class. Accepts a path, container, height, width, and change handler. * Although it doesn't need a handler. We can just call get path and let it do that. * The checks can be handled outside. We don't need to do it inside. */ class Meanderer { container height path threshold width constructor({ height, path, threshold = 0.2, width }) { this.height = height this.path = path this.threshold = threshold this.width = width // With what we are given create internal references this.aspect_ratio = width / height // Convert the path .........完整代码请登录后点击上方下载按钮下载查看
网友评论0