Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Animation
Branding
Illustration
css
nav { position: relative; z-index: 1; } nav ul { margin: 0; padding: 0; list-style: none; display: flex; gap: 40px; } nav ul li button { -webkit-appearance: none; -moz-appearance: none; appearance: none; border: none; cursor: pointer; background-color: transparent; padding: 0; margin: 0; font-family: "Inter"; font-weight: 600; font-size: 16px; list-style: 22px; color: #5C5B66; transition: color 0.25s; } nav ul li.active button { color: #fff; } nav ul li:not(.active):hover button { color: #807E8C; } nav .active-element { --active-element-scale-x: 1; --active-element-scale-y: 1; --active-element-show: 0; --active-element-opacity: 0; --active-element-width: 0px; --active-element-strike-x: 0%; --active-element-mask-position: 0%; position: absolute; left: 0; top: 34px; height: 3px; width: 36px; border-radius: 2px; background-color: #fff; opacity: var(--active-element-show); } nav .active-element > svg, nav .active-element .strike { position: absolute; right: 0; top: 50%; transform: translateY(-50%); opacity: var(--active-element-opacity); width: var(--active-element-width); mix-blend-mode: multiply; } nav .active-element > svg { display: block; overflow: visible; height: 5px; filter: blur(0.5px) drop-shadow(2px 0px 8px rgba(0, 117, 255, 0.4)) drop-shadow(1px 0px 2px rgba(0, 128, 255, 0.8)) drop-shadow(0px 0px 3px rgba(153, 204, 255, 0.4)) drop-shadow(2px 0px 8px rgba(137, 196, 255, 0.45)) drop-shadow(8px 0px 16px rgba(153, 204, 255, 0.5)); } nav .active-element .strike { padding: 24px 0; -webkit-mask-image: linear-gradient(to right, transparent calc(0% + var(--active-element-mask-position)), black calc(15% + var(--active-element-mask-position)), black 80%, transparent); mask-image: linear-gradient(to right, transparent calc(0% + var(--active-element-mask-position)), black calc(15% + var(--active-element-mask-position)), black 80%, transparent); } nav .active-element .strike svg { display: block; overflow: visible; height: 12px; width: calc(var(--active-element-width) * 2); transform: translate(var(--active-element-strike-x), 30%) scale(var(--active-element-scale-x), var(--active-element-scale-y)); } nav .active-element .strike svg:last-child { transform: translate(var(--active-element-strike-x), -30%) scale(-1); } nav .active-element .strike svg g path:nth-child(2) { filter: blur(2px); } nav .active-element .strike svg g path:nth-child(3) { filter: blur(4px); } nav.before .active-element { transform: rotateY(180deg); } html { box-sizing: border-box; -webkit-font-smoothing: antialiased; } * { box-sizing: inherit; } *:before, *:after { box-sizing: inherit; } body { min-height: 100vh; display: flex; justify-content: center; align-items: center; background-color: #020112; position: relative; overflow: hidden; } body:before { content: ""; position: absolute; inset: 40% -60% 0 -60%; background-image: radial-gradient(ellipse at bottom, #152B9D 0%, #020112 50%); opacity: 0.3; pointer-events: none; } body .twitter { position: fixed; display: block; right: 12px; bottom: 12px; } body .twitter svg { width: 32px; height: 32px; fill: #fff; }
JavaScript
const navElement = document.querySelector("nav"); const activeElement = document.createElement("div"); activeElement.classList.add("active-element"); const getOffsetLeft = (element) => { const elementRect = element.getBoundingClientRect(); return ( elementRect.left - navElement.getBoundingClientRect().left + (elementRect.width - activeElement.offsetWidth) / 2 ); }; navElement.appendChild(activeElement); const activeButton = navElement.querySelector("ul li.active button"); document.fonts.ready.then(() => { gsap.set(activeElement, { x: getOffsetLeft(activeButton), }); gsap.to(activeElement, { "--active-element-show": "1", duration: 0.2, }); }); navElement.querySelectorAll("ul li button").forEach((button, index) => { button.addEventListener("click", () => { const active = navElement.querySelector("ul li.active"); const oldIndex = [...active.parentElement.children].indexOf(active); if ( index === oldIndex || navElement.classList.contains("before") || navElement.classList.contains("after") ) { return; } const x = getOffsetLeft(button); const direction = index > oldIndex ? "after" : "before"; const spacing = Math.abs(x - getOffsetLeft(active)); navElement.classList.add(direction); active.classList.remove("active"); button.parentElement.classList.add("active"); gsap.set(activeElement, { rotateY: direction === "before" ? "180deg" : "0deg", }); gsap.to(activeElement, { keyframes: [ { "--active-element-width": `${ spacing > navElement.offsetWidth - 60 ? navElement.offsetWidth - 60 : spacing }px`, duration: 0.3, ease: "none", onStart: () => { createSVG(activeElement); gsap.to(activeElement, { "--active-element-opacity": 1, duration: 0.1, }); }, }, { "--active-element-scale-x": "0", "--active-element-scale-y": ".25", "--active-element-width": "0px", duration: 0.3, onStart: () => { gsap.to(activeElement, { "--active-element-mask-position": "40%", duration: 0.5, }); gsap.to(activeElement, { "--active-element-opacity": 0, delay: 0.45, duration: 0.25, }); }, onComplete: () => { activeElement.innerHTML = ""; navElement.classList.remove("before", "after"); activeElement.removeAttribute("style"); gsap.set(activeElement, { x: getOffsetLeft(button), "--active-element-show": "1", }); }, }, ], }); gsap.to(activeElement, { x, "--active-element-strike-x": "-50%", duration: 0.6, ease: "none", }); }); }); const createSVG = (element) => { element.innerHTML = `
`; };
粒子
时间
文字
hover
canvas
3d
游戏
音乐
火焰
水波
轮播图
鼠标跟随
动画
css
加载动画
导航
菜单
按钮
滑块
tab
弹出层
统计图
svg
×
Close
在线代码下载提示
开通在线代码永久免费下载,需支付20jQ币
开通后,在线代码模块中所有代码可终身免费下!
您已开通在线代码永久免费下载,关闭提示框后,点下载代码可直接下载!
您已经开通过在线代码永久免费下载
对不起,您的jQ币不足!可通过发布资源 或
直接充值获取jQ币
取消
开通下载
<!doctype html> <html> <head> <meta charset="utf-8"> <title>标签栏动画-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号