gsap+svg实现多边形洞穴变动动画效果代码
代码语言:html
所属分类:动画
代码描述:gsap+svg实现多边形洞穴变动动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <style> body { background-color: #FFFCF9; overflow: hidden; text-align:center; display: flex; align-items: center; justify-content: center; } body, html { height: 100%; width: 100%; margin: 0; padding: 0; } svg { width: 100%; height: 100%; visibility: hidden; } .wave, #myPath { stroke-width: 0; stroke-linecap: round; stroke-linejoin: round; stroke: #56acf4; } </style> </head> <body> <svg id="mainSVG" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 800 600"> <defs> <filter id='innerShadow'> <!-- Shadow offset --> <feOffset dx='0' dy='0' /> <!-- Shadow blur --> <feGaussianBlur stdDeviation='10' result='offset-blur' /> <!-- Invert drop shadow to make an inset shadow --> <feComposite operator='out' in='SourceGraphic' in2='offset-blur' result='inverse' /> <!-- Cut color inside shadow --> <feFlood flood-color='#231F27' flood-opacity='0.35' result='color' /> <feComposite operator='in' in='color' in2='inverse' result='shadow' /> <!-- Placing shadow over element --> <feComposite operator='over' in='shadow' in2='SourceGraphic' /> </filter> <circle class="dot" r="3" cx="0" cy="0" /> <polygon class="wave" /> </defs> </svg> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.10.4.js"></script> <script> gsap.config({trialWarn: false}); let select = s => document.querySelector(s), selectAll = s => document.querySelectorAll(s), mainSVG = select('#mainSVG'), wave = select('.wave'), dot= select('.dot'), colorArr = ['#F5F5F5','#8DC3BF', '#31A9C1', '#3F95BD', '#1D699B', '#13438D', '#231F27'], numDots = colorArr.length, stageSize = {width: 800, height: 600} function calcDirection(id, radius, points) { let rX = gsap.utils.random(radius - 20, radius + 20); let rY = gsap.utils.random(radius - 20, radius + 20); let dirX = points[id].x; let dirY = points[id].y; let val = 0.6; dirX = gsap.utils.interpolate( points[id].x, stageSize.width/2, val);//+= (Math.cos((id * step) * Math.PI / 180) * 2 ) + stageSize.width/2; dirY = gsap.utils.interpolate(points[id].y, stageSize.height/2, val)//(.........完整代码请登录后点击上方下载按钮下载查看
网友评论0