TweenMax实现文字菜单鼠标悬浮图片跟随显示效果代码
代码语言:html
所属分类:菜单导航
代码描述:TweenMax实现文字菜单鼠标悬浮图片跟随显示效果代码
代码标签: TweenMax 文字 菜单 鼠标 悬浮 图片 跟随 显示
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> @import url("https://fonts.googleapis.com/css?family=Montserrat:900"); *, *::after, *::before { box-sizing: border-box; } body { background-color: #1a1a1a; } a { text-decoration: none; color: var(--color-link); outline: none; font-family: "Montserrat", sans-serif; } a + a { margin-top: 30px; } .content { display: flex; height: 100vh; justify-content: center; flex-direction: column; width: 100%; overflow: hidden; position: relative; align-items: center; } .distort { position: absolute; pointer-events: none; will-change: transform; } .distort__img { opacity: 0; } .menu { display: flex; flex-direction: column; align-items: stretch; text-align: center; font-size: 10vh; font-weight: normal; } .menu__link { z-index: 999; color: #fff; position: relative; white-space: nowrap; } .menu__link:hover { color: #fff; opacity: 0.85; } </style> </head> <body translate="no"> <div class="content"> <svg class="distort" width="350" height="450" viewBox="0 0 350 450"> <filter id="distortionFilter"> <feTurbulence type="turbulence" baseFrequency="0.07 0.01" numOctaves="5" seed="2" stitchTiles="stitch" x="0%" y="0%" width="100%" height="100%" result="noise"/> <feDisplacementMap in="SourceGraphic" in2="noise" scale="0" xChannelSelector="R" yChannelSelector="B" x="0%" y="0%" width="100%" height="100%" filterUnits="userSpaceOnUse"/> </filter> <g filter="url(#distortionFilter)"> <image class="distort__img" x="50" y="50" xlink:href="https://images.unsplash.com/photo-1530092285049-1c42085fd395?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fHNwcmluZ3xlbnwwfHwwfHx8MA%3D%3D" height="350" width="250"/> <image class="distort__img" x="50" y="50" xlink:href="https://images.unsplash.com/photo-1532347922424-c652d9b7208e?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NHx8c3VtbWVyfGVufDB8fDB8fHww" height="350" width="250"/> <image class="distort__img" x="50" y="50" xlink:href="https://images.unsplash.com/photo-1543837173-6c26bc89937b?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8OHx8YXV0dW1ufGVufDB8fDB8fHww" height="350" width="250"/> <image class="distort__img" x="50" y="50" xlink:href="https://images.unsplash.com/photo-1551582045-6ec9c11d8697?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8N3x8d2ludGVyfGVufDB8fDB8fHww" height="350" width="250"/> </g> </svg> <nav class="menu"> <a href="#" class="menu__link">Spring</a> <a href="#" class="menu__link">Summer</a> <a href="#" class="menu__link">Autumn</a> <a href="#" class="menu__link">Winter</a> </nav> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/TweenMax.min.js"></script> <script > { const body = document.body; const docEl = document.documentElement; const lineEq = (y2, y1, x2, x1, currentVal) => { // y = mx + b var m = (y2 - y1) / (x2 - x1),b = y1 - m * x1; return m * currentVal + b; }; const lerp = (a, b, n) => (1 - n) * a + n * b; const distance = (x1, x2, y1, y2) => { var a = x1 - x2; var b = y1 - y2; return Math.hypot(a, b); }; const getMousePos = e => { let posx = 0; let posy = 0; if (!e) e = window.event; if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; } else if (e.clientX || e.clientY) { posx = e.clientX + document.body.scrollLeft + document..........完整代码请登录后点击上方下载按钮下载查看
网友评论0