Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
News & Politics
Culture
Technology
Business
Human Interest
Works
Articles
About
Contact Me
My Books
css
body { padding: 1rem; font-family: 'IBM Plex Sans', sans-serif; background-color: #fff8ae; } svg { display: block; } .group { padding: 1rem; margin-bottom: 2.5rem; } .c-nav:not(:last-child) { margin: 1rem 0 2rem; } @media (min-width: 900px) { .c-nav { display: flex; justify-content: center; } } .c-nav__item { margin-right: 1.5rem; font-size: 1.5rem; } .c-nav__item a { display: inline-block; text-decoration: none; color: #000; margin-bottom: 4px; transition: 0.4s; } .c-nav__item svg { pointer-events: none; transition: 0.5s; } .c-nav__item path { transition: stroke-dasharray 0.5s, stroke-dashoffset 0.5s, opacity 0.5s; } .c-nav__item path:last-child { opacity: 0.2; } .c-nav__item a:hover, .c-nav__item a:focus { color: #00bc9b; } .c-nav__item a:hover + svg, .c-nav__item a:focus + svg { opacity: 1; } .c-nav__item a:hover + svg path, .c-nav__item a:focus + svg path { stroke-dashoffset: 0; } #path1 { opacity: 0.25; } .c-form { max-width: 500px; margin: 0 auto; } .c-form legend { margin-bottom: 1rem; font-weight: bold; } .c-form label { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .c-form__item { margin-bottom: 1rem; } .c-nav-2 .c-nav__item { font-size: 1rem; } hr { border: 0; height: 1px; background: lightgrey; } .ishadeed { text-align: center; } .ishadeed a { color: #3563D9; }
JavaScript
class Underliner { constructor(selector, color1, color2, thickness1, thickness2, strokeLinecap, rtl) { this.links = document.querySelectorAll(selector) this.fill = 'transparent'; this.color1 = color1; this.color2 = color2; this.thickness1 = thickness1; this.thickness2 = thickness2; this.strokeLinecap = strokeLinecap; this.rtl = rtl; this.init(); } init() { let self = this; self.links.forEach(function (link) { let linkWidth = parseInt(link.offsetWidth); let svg = self.createSVG(linkWidth); self.insertAfter(svg, link); }); } setPath(pathD, color, thickness, strokeLinecap) { const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); path.setAttribute("d", pathD); path.setAttribute("fill", this.fill); path.setAttribute("stroke", color); path.setAttribute("stroke-width", thickness); path.setAttribute("stroke-linecap", strokeLinecap); path.setAttribute("stroke-dasharray", path.getTotalLength() + 10); path.setAttribute("stroke-dashoffset", path.getTotalLength() + 10); return path; } randomizePath(linkWidth) { let moveYMin = 5; let moveYMax = 12; let curveXMin = 15; let curveXMax = linkWidth; /* Width of the link */ let curveYMin = 7; let curveYMax = linkWidth * 0.12; /* Making the quadratic propotional to the link width */ //let curveYMax = 20 let endYMin = 5; let endYMax = 11; let moveY = Math.floor(Math.random() * (moveYMax - moveYMin)) + moveYMin; let curveX = Math.floor(Math.random() * (curveXMax - curveXMin)) + curveXMin; let curveY = Math.floor(Math.random() * (curveYMax - curveYMin)) + curveYMin; let endY = Math.floor(Math.random() * (endYMax - endYMin)) + endYMin; return `M5 ${moveY} Q ${curveX} ${curveY} ${linkWidth - 7} ${endY}` } createSVG(linkWidth) { const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg"); svg.setAttribute("width", linkWidth); svg.setAttribute("height", "35"); const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); const path2 = document.createElementNS("http://www.w3.org/2000/svg", "path"); let pathD = this.randomizePath(linkWidth); let pathD2 = this.randomizePath(linkWidth); if(this.rtl === true) { pathD = this.reverseMe(pathD); pathD2 = this.reverseMe(pathD2); } svg.appendChild(this.setPath(pathD, this.color1, this.thickness1, this.strokeLinecap)); svg.appendChild(this.setPath(pathD2, this.color2, this.thickness2, this.strokeLinecap)); svg.setAttribute("focusable", false); return svg; } reverseMe(path) { /* Regex functions borrwed from https://github.com/krispo/svg-path-utils/blob/master/src/svg-path-utils.js */ let pathOperators = path.replace(/[\d,\-\s]+/g, '').split(''); let pathNums = path.replace(/[A-Za-z,]+/g, ' ').trim().replace(/\s\s+/g, ' ').split(' '); return `${pathOperators[0]} ${pathNums[4]} ${pathNums[5]} ${pathOperators[1]} ${pathNums[2]} ${pathNums[3]} ${pathNums[0]} ${pathNums[1]}`; } insertAfter(el, referenceNode) { referenceNode.parentNode.insertBefore(el, referenceNode.nextSibling); } } let test = new Underliner(".underliner a", "url(#gradient)", "url(#gradient2)", 7, 12, "round", false); let test2 = new Underliner(".underliner-small a", "url(#gradient)", "url(#gradient2)", 3, 6, "round");
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>svg导航鼠标悬停动画-jq22.com</title> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <style>
</style> </head> <body>
<script>
</script>
</body> </html>
2012-2021 jQuery插件库版权所有
jquery插件
|
jq22工具库
|
网页技术
|
广告合作
|
在线反馈
|
版权声明
沪ICP备13043785号-1
浙公网安备 33041102000314号