Tween+three+hex-grid实现炫酷蜂窝六边形按住不放动画效果代码
代码语言:html
所属分类:动画
代码描述:Tween+three+hex-grid实现炫酷蜂窝六边形按住不放动画效果代码
代码标签: Tween three hex-grid 炫酷 蜂窝 六边形 按住 不放 动画
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css2?family=PT+Sans+Narrow:wght@400;700&display=swap"); body { margin: 0; padding: 0; } #grid { width: 100vw; height: 100vh; background: #16dfaa; } .k-hold { position: absolute; top: 50%; left: 50%; width: 354px; height: 354px; margin-left: -177px; margin-top: -177px; cursor: pointer; } .k-black { display: block; width: 354px; height: 354px; position: absolute; top: 0; left: 0; } .k-enter { display: block; width: 354px; height: 354px; position: absolute; top: 0; left: 0; border: none; background: transparent; cursor: pointer; color: #fff; font-size: 40px; text-transform: uppercase; font-family: "PT Sans Narrow", Impact, sans-serif; font-weight: 700; } .k-stroke { opacity: 1; stroke-linecap: round; stroke-linejoin: mitter; stroke-dasharray: 1000; stroke-dashoffset: 1000; } .k-black__stroke { position: absolute; top: 0; left: 0; right: 0; bottom: 0; -webkit-transform: translateZ(100px) scaleX(-1); transform: translateZ(100px) scaleX(-1); } .k-black__stroke svg { position: absolute; top: 50%; left: 50%; -webkit-transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0); } </style> </head> <body translate="no"> <div id="grid"></div> <div class="k-hold"> <div class="k-black"> <div class="k-black__stroke"> <svg width="252" height="289" viewBox="0 0 252 289"> <polygon class="k-stroke" fill="transparent" stroke="#00AA86" stroke-width="4" points="126 1, 249 72, 249 216, 126 288, 2 216, 1 72"></polygon> </svg> </div> </div> <button type="button" class="k-enter"> Hold me </button> </div> <script type="module"> import { Tween, Easing } from '//repo.bfw.wiki/bfwrepo/js/tween.esm.js'; let r = null; const $button = $(".k-enter"); const stroke = document.querySelector("polygon.k-stroke"); const progress = { value: 1000 }; const tween = new Tween(progress) .easing(Easing.Cubic.Out) .onUpdate(function() { stroke.style.setProperty("stroke-dashoffset", progress.value); }); function forward() { tween.stop().to({ value: 2000 }, 3000).startFromCurrentValues(); } function reverse() { tween.stop().to({ value: 1000 }, 3000).startFromCurrentValues(); } $button.on("mousedown touchstart", function(e) { e.preventDefault(); e.stopPropagation(); forward(); r = window.setTimeout(function() { $button.html('Clicked'); }, 3000); }); $button.on("mouseup touchend", function() { reverse(); $button.html('Hold me'); window.clearTimeout(r); }); function animate(time) { t.........完整代码请登录后点击上方下载按钮下载查看
网友评论0