Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Item One
Item Two
Item Three
css
:root { --primary-color: #90caf9; --accent-color: #f48fb1; --grey-700-color: #423f3f; --grey-900-color: #333333; --base-spacing: 8px; --font-m: 14px; --shadow-small: 0px 2px 4px -1px rgb(0 0 0 / 20%), 0px 4px 5px 0px rgb(0 0 0 / 14%), 0px 1px 10px 0px rgb(0 0 0 / 12%); } body { display: flex; align-items: center; justify-content: center; height: 100vh; margin: 0; padding: 0; background-color: var(--grey-900-color); } .tabs-box { display: flex; justify-content: center; max-width: 640px; height: 48px; width: 100%; background-color: var(--primary-color); box-shadow: var(--shadow-small); border-top-left-radius: 3px; border-top-right-radius: 3px; } .tabs-menu { display: flex; justify-content: center; position: relative; } .tab-button { display: flex; justify-content: center; align-items: center; border: none; position: relative; overflow: hidden; font-weight: 500; font-size: var(--font-m); color: var(--grey-700-color); text-transform: uppercase; letter-spacing: 0.02857em; white-space: normal; letter-spacing: 0.02857em; background-color: transparent; padding: var(--base-spacing) calc(var(--base-spacing) * 2); cursor: pointer; transition: color 250ms ease-in; } .tab-button .active { color: var(--grey-700); } .tab-button__content { display: block; pointer-events: none; } .tab-button:hover, .tab-button:focus { outline: none; color: var(--grey-700) } .tab-indicator { background-color: var(--accent-color); height: 3px; position: absolute; left: 0; bottom: 0; transition: left 250ms ease-in-out, width 650ms ease-in-out; } .tab-button__ripple { position: absolute; background-color: black; transform: translate(-50%, -50%); border-radius: 50%; animation: ripple 1000ms linear infinite; pointer-events: none; } .focus::after { content: ''; position: absolute; background-color: black; opacity: .2; border-radius: 50%; width: 80%; height: auto; padding-top: 80%; background: black; transition: transform 300ms ease-in-out; transform: scale(0); animation: focusRipple 300ms linear infinite, focusPulse 1700ms linear 300ms infinite; } @keyframes ripple { 0% { width: 0; height: 0; opacity: .4; } 100% { width: 500px; height: 500px; opacity: 0; } } @keyframes focusRipple { 0% { transform: scale(0); } 100% { transform: scale(1); } } @keyframes focusPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
JavaScript
const ACTIVE_CLASS = 'active' const tabItems = document.querySelectorAll('.js-tab-button'); const indicator = document.querySelector('.js-tab-indicator'); const tabsMenu = document.querySelector('.js-tabs-menu'); const indicatorPosition = tabItems[0].getBoundingClientRect().left - tabsMenu.getBoundingClientRect().left; indicator.style.width = `${tabItems[0].clientWidth}px`; tabItems.forEach(tab => { tab.setAttribute('aria-selected', 'false'); tab.addEventListener('click', (e) => { handleTabSelection(e); const current = document.querySelector(`.focus`); if(current) { current.className = current.className.replace(` focus`, ''); } }) tab.addEventListener('mousedown', handleRippleEffect); tab.addEventListener('keydown', handleArrowKeysFocus); }); function handleTabSelection(e) { toggleActiveClass(e); moveTabIndicator(e); handleA11y(e); } function toggleActiveClass(e) { const current = document.querySelector(`.${ACTIVE_CLASS}`); if(current) { current.className = current.className.replace(` ${ACTIVE_CLASS}`, ''); } e.target.className += ` ${ACTIVE_CLASS}`; } function toggleFocusClass(e) { const current = document.querySelector(`.focus`); if(current) { current.className = current.className.replace(` focus`, ''); } e.currentTarget.className += ` focus`; } function moveTabIndicator(e) { const indicatorPosition = e.target.getBoundingClientRect().left - tabsMenu.getBoundingClientRect().left; indicator.style.width = `${e.target.clientWidth}px`; indicator.style.left = `${indicatorPosition}px`; } function handleRippleEffect(e) { const posX = e.target.offsetLeft; const posY = e.target.offsetTop; const span = document.createElement('span'); const x = e.pageX - e.target.getBoundingClientRect().left; const y = e.pageY - e.target.getBoundingClientRect().top; span.classList.add('tab-button__ripple'); e.target.appendChild(span); span.style.left = `${x}px`; span.style.top = `${y}px`; setTimeout(() => { span.remove(); }, 1000); } function handleA11y(e) { tabItems.forEach(tab => { const addActiveFocus = () => { e.target.setAttribute('aria-selected', 'true') e.target.setAttribute('tabindex', '0'); }; const removeActiveFocus = () => { tab.setAttribute('aria-selected', 'false'); tab.setAttribute('tabindex', '-1'); }; tab === e.target ? addActiveFocus() : removeActiveFocus(); }); } function handleArrowKeysFocus(e) { const totalTabItems = tabItems.length - 1; const leftArrowKey = e.which === 37; const rightArrowKey = e.which === 39; let index = Array.prototype.indexOf.call(tabItems, e.currentTarget); let newIndex; const decrementIndex = () => { newIndex = index - 1; if (newIndex < 0) { newIndex = totalTabItems; } } const incrementIndex = () => { newIndex = index + 1; if (newIndex > totalTabItems) { newIndex = 0; } } if (leftArrowKey) { decrementIndex(); toggleFocusClass(e); } if (rightArrowKey) { incrementIndex(); toggleFocusClass(e); } const current = document.querySelector(`.focus`); if(current) { current.className = current.className.replace(` focus`, ''); } if (tabItems[newIndex]) { tabItems[newIndex].className += ` focus`; tabItems[newIndex].focus(); } } // Initially activate the first tab tabItems[0].setAttribute('tabindex', '0'); tabItems[0].setAttribute('aria-selected', 'true');
粒子
时间
文字
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号