TweenMax+MorphSVGPlugin实现绿色小草生长随风摇摆动画效果代码
代码语言:html
所属分类:动画
代码描述:TweenMax+MorphSVGPlugin实现绿色小草生长随风摇摆动画效果代码
代码标签: TweenMax MorphSVGPlugin 绿色 小草 生长 随风 摇摆 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { height: 100vh; overflow: hidden; } #stage { position: relative; width: 800px; height: 600px; top: 100%; left: 50%; transform: translate(-50%, -100%); } path { fill: none; stroke: green; } button { border: 1px solid rgba(0, 0, 0, 0.2); font-weight: bold; box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.37); text-transform: uppercase; transition: all 0.5s ease; line-height: 1.6; padding: 8px 18px; background: #FFC107; color: #555; } button:focus { outline: none; } button:hover { border: 1px solid rgba(0, 0, 0, 0.5); color: #000; } .hud { position: absolute; top: 0; left: 0; padding: 15px; } </style> </head> <body> <!-- partial:index.partial.html --> <div class="hud"> <button id="rise">RISE UP</button> </div> <svg id="stage"></svg> <!-- partial --> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/MorphSVGPlugin3.min.js"></script> <script > console.clear(); var log = console.log.bind(console); class Grass { constructor(path, offset, width, height, minHeight, maxHeight, maxAngle, startAngle) { this.path = path; this.width = random(4, 8); this.height = random(150, maxHeight); this.maxAngle = random(10, maxAngle); this.angle = Math.random() * randomSign() * startAngle * Math.PI / 180; var offsetX = 1.5; // Start position var sx = offset / 2 + random(width - offset); var sy = height; // Curvature var csx = sx - offsetX; var csy = sy - this.height / (Math.random() < 0.5 ? 1 : 2); // Parallel point var psx = csx; var psy = csy; var dx = sx + this.width; var dy = sy; this.coords = [sx, sy, csx, csy, psx, psy, dx, dy]; this.growing = false; this.morphed = false; this.start = 0; this.elapsed = 0; this.height_ = this.height; this.height = random(200, Math.min(500, this.height)); var ambient = 0.85; var color = [ Math.floor(random(16, 48) * ambient), Math.floor(random(100, 255) * ambient), Math.floor(random(16, 48) * ambient)]; var w = this.width / 2; var d = `M${sx},${sy + 2},h${w},h${w}z`; TweenLite.set(path, { fill: `rgb(${color})`, attr: { d } }); } rise() { this.morphed = true; this.growing = false; .........完整代码请登录后点击上方下载按钮下载查看
网友评论0