Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
One
Two
Three
Four
Five
css
html { box-sizing: border-box; } *, *:before, *:after { box-sizing: inherit; } html, body { height: 100%; } :root { --active-indicator-width: 120px; --icon-width: 26px; --icon-margin-right: 9px; --menu-padding-horizontal: 29px; --menu-padding-vertical: 20px; --active-indicator-extra-length: 12px; /* We want the indicator to be longer than the actual buttons themselves, this length is added to both sides of the indicator */ --space-between-icons: 32px; } @media (max-width: 600px) { :root { --active-indicator-width: 80px; --icon-margin-right: 7px; --menu-padding-horizontal: 24px; } } body { margin: 0; display: flex; align-items: center; justify-content: center; background: #297bf7; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } .nav { background: #fff; padding: var(--menu-padding-vertical) var(--menu-padding-horizontal); display: flex; box-shadow: 0 0 14px 0 rgba(0, 0, 0, 0.1); border-radius: 1px; position: relative; } .nav__active-indicator { position: absolute; top: 50%; margin-left: calc( var(--menu-padding-horizontal) - var(--active-indicator-extra-length) ); left: 0; transform: translateY(-50%); width: calc( var(--active-indicator-width) + var(--active-indicator-extra-length) * 2 ); height: calc(100% - var(--menu-padding-vertical)); background: #f7c329; z-index: 10; border-radius: var(--active-indicator-width); transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1); } .nav__item { margin-left: var(--space-between-icons); position: relative; z-index: 20; } .nav__item:first-child { margin-left: 0; } button { padding: 0; border: 0; display: flex; align-items: center; cursor: pointer; width: var(--icon-width); transition: width 0.3s cubic-bezier(0.215, 0.61, 0.355, 1); /* I knowwww, don't animate width, but it doesn't actually look jittery in this case - so maybe it just works in this case? If not there are alternatives we can try */ outline: none; position: relative; background: transparent; } .active { width: var(--active-indicator-width); } .icon { display: block; margin-right: var(--icon-margin-right); flex-shrink: 0; width: var(--icon-width); height: var(--icon-width); } .icon path { fill: #a6adb1; transition: fill 0.2s; } .active .icon path { fill: #000; } .text { display: block; color: rgba(0, 0, 0, 0); pointer-events: none; font-size: 0; } .text:after { content: attr(data-title); position: absolute; top: 0; left: 0; width: var(--active-indicator-width); height: 100%; opacity: 0; display: flex; align-items: center; font-size: 15px; font-weight: bold; color: #000; padding-left: calc(var(--icon-width) + var(--icon-margin-right)); transition: opacity 0s; } .slide-right .text:after { left: 0; right: auto; } .slide-left .text:after { right: 0; left: auto; } .active .text:after { opacity: 1; transition: opacity 0.4s; }
JavaScript
// --------- // Variables // --------- const nav = document.querySelector(".nav"); const navActiveIndicator = document.querySelector(".nav__active-indicator"); const buttons = document.querySelectorAll("button"); let activeButton = document.querySelector(".active"); // --- // App // --- setIndexKey(buttons); buttons.forEach(button => { button.addEventListener("click", buttonClick); }); // --------- // Functions // --------- function setIndexKey(arrayOfElements) { arrayOfElements.forEach((element, index) => { element.index = index; }); } function buttonClick() { // Position the text so that it appears to not move with the button width growth if (this.index > activeButton.index) { nav.classList.remove("slide-right"); nav.classList.add("slide-left"); } else { nav.classList.remove("slide-left"); nav.classList.add("slide-right"); } // Animate the active indicator position const iconWidth = parseInt( getComputedStyle(document.documentElement).getPropertyValue("--icon-width")); const spaceBetweenIcons = parseInt( getComputedStyle(document.documentElement).getPropertyValue( "--space-between-icons")); navActiveIndicator.style.transform = `translateX(${(iconWidth + spaceBetweenIcons) * this.index}px) translateY(-50%)`; // Update the active button if (activeButton) activeButton.classList.remove("active"); this.classList.add("active"); activeButton = this; }
粒子
时间
文字
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号