Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
language
Locations
Amsterdam
Berlin
Dublin
London
Melbourne
San Francisco
Warsaw
css
body{background-color: #2D2D2D} * { padding: 0; margin: 0; box-sizing: border-box; font-family: "Roboto", sans-serif; } .material-icons { font-size: 1.5rem; color: rgba(0, 0, 0, 0.54); vertical-align: middle; line-height: 100%; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .app-canvas { display: flex; justify-content: center; padding-top: 100px; } .menubox { position: relative; display: inline-block; background: white; border: 1px solid #dbdbdb; border-radius: 6px; -webkit-transform-origin: top center; transform-origin: top center; overflow: hidden; transition: border-radius .25s ease-in-out; } .menubox:focus, .menubox:focus-within { outline: none; border-color: #c2c2c2; } .menubox:focus::after, .menubox:focus-within::after { content: ''; height: 100%; width: 100%; position: absolute; border-radius: inherit; border: inherit; border-width: 2px; left: -2px; top: -2px; } .menubox.menubox--collapsed { border-radius: 50px; } .menubox__label { position: relative; color: #595959; font-weight: 500; font-size: 0.875rem; letter-spacing: 0.05rem; padding: 0.625rem 5rem 0.625rem 1rem; background: #f9f9f9; -webkit-transform-origin: top center; transform-origin: top center; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .menubox__label-text { line-height: 100%; vertical-align: middle; position: relative; left: 0.25rem; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .menubox__label::after { content: ''; width: 1px; height: 1px; right: 1rem; top: 0; bottom: 0; margin: auto; position: absolute; display: inline-block; border-top: 5px solid #595959; border-left: 4px solid transparent; border-right: 4px solid transparent; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; transition: -webkit-transform .25s ease-in-out; transition: transform .25s ease-in-out; transition: transform .25s ease-in-out, -webkit-transform .25s ease-in-out; } .menubox--collapsed .menubox__label::after { -webkit-transform: rotateZ(-90deg); transform: rotateZ(-90deg); } .menubox__contents { padding: 0.5rem 0; -webkit-transform-origin: top center; transform-origin: top center; border-top: 1px solid #dbdbdb; } .menubox__options { list-style-type: none; } .menubox__option { position: relative; } .menubox__option-label { position: relative; color: gray; transition: all .35s ease-out; z-index: 1; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } .menubox__option-toggle { display: block; font-weight: 400; font-size: 0.875rem; padding: 0.5rem 4rem 0.5rem 1rem; cursor: pointer; -webkit-animation: entrance .4s ease-out; animation: entrance .4s ease-out; } .menubox__option-toggle::before { content: ''; position: absolute; width: calc(100% - 0.25rem); height: calc(100% - 2px); left: 0; top: 0; border-radius: 0 50px 50px 0; opacity: 0; background: #f9f9f9; -webkit-transform: scaleX(0); transform: scaleX(0); -webkit-transform-origin: left center; transform-origin: left center; transition: opacity .25s ease-out, -webkit-transform .25s ease-out; transition: opacity .25s ease-out, transform .25s ease-out; transition: opacity .25s ease-out, transform .25s ease-out, -webkit-transform .25s ease-out; } @-webkit-keyframes entrance { from { opacity: 0; -webkit-transform: translateY(-15px); transform: translateY(-15px); } to { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } } @keyframes entrance { from { opacity: 0; -webkit-transform: translateY(-15px); transform: translateY(-15px); } to { opacity: 1; -webkit-transform: translateY(0px); transform: translateY(0px); } } .menubox__option-toggle:hover::before, .menubox__option-toggle:focus-within::before { opacity: 1; -webkit-transform: scaleX(1); transform: scaleX(1); } .menubox__option-toggle:hover .menubox__option-label, .menubox__option-toggle:focus-within .menubox__option-label { color: #4d4d4d; } .menubox__option-toggle:hover::before { border: 1px solid #e8e8e8; border-left: 0; } .menubox__option-toggle:focus-within::before { background: whitesmoke; } .menubox__option-toggle input[type=checkbox] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; clip: rect(1px 1px 1px 1px); -webkit-clip-path: inset(50%); clip-path: inset(50%); overflow: hidden; } .menubox__option-toggle input[type=checkbox] ~ .menubox__option-toggle-check { position: absolute; top: 0; right: 0.375rem; width: 2rem; height: 100%; } .menubox__option-toggle input[type=checkbox]:checked ~ .menubox__option-label { color: #606060; font-weight: 500; } .menubox__option-toggle input[type=checkbox]:checked ~ .menubox__option-toggle-check { -webkit-animation: tick 1s ease-out 25ms backwards; animation: tick 1s ease-out 25ms backwards; } @-webkit-keyframes tick { 0% { -webkit-clip-path: inset(0 60% 50% 0); clip-path: inset(0 60% 50% 0); } 60%, 100% { -webkit-clip-path: inset(0); clip-path: inset(0); } } @keyframes tick { 0% { -webkit-clip-path: inset(0 60% 50% 0); clip-path: inset(0 60% 50% 0); } 60%, 100% { -webkit-clip-path: inset(0); clip-path: inset(0); } } .menubox__option-toggle input[type=checkbox]:checked ~ .menubox__option-toggle-check, .menubox__option-toggle input[type=checkbox] ~ .menubox__option-toggle-check.unchecking { background: transparent url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiM2MWJmOWUiIHN0cm9rZS13aWR0aD0iMyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIj48cG9seWxpbmUgcG9pbnRzPSIyMCA2IDkgMTcgNCAxMiI+PC9wb2x5bGluZT48L3N2Zz4=) center/45% no-repeat; } .menubox__option-toggle input[type=checkbox] ~ .menubox__option-toggle-check.unchecking { -webkit-animation: untick .35s ease-out backwards; animation: untick .35s ease-out backwards; } @-webkit-keyframes untick { 0% { -webkit-clip-path: inset(0); clip-path: inset(0); } 60% { -webkit-clip-path: inset(0 60% 0 0); clip-path: inset(0 60% 0 0); } 80%, 100% { -webkit-clip-path: inset(0 100% 100% 0); clip-path: inset(0 100% 100% 0); } } @keyframes untick { 0% { -webkit-clip-path: inset(0); clip-path: inset(0); } 60% { -webkit-clip-path: inset(0 60% 0 0); clip-path: inset(0 60% 0 0); } 80%, 100% { -webkit-clip-path: inset(0 100% 100% 0); clip-path: inset(0 100% 100% 0); } }
JavaScript
const menubox = document.querySelector('.menubox'); const menulabel = menubox.querySelector('.menubox__label'); const menucontent = menubox.querySelector('.menubox__contents'); const menuchecks = menubox.querySelectorAll('input[type=checkbox]'); const menuboxRect = menubox.getBoundingClientRect(); const menulabelRect = menulabel.getBoundingClientRect(); const frameTime = 1000 / 60; const duration = 350; const frames = Math.ceil(duration / frameTime); const slideHeight = menuboxRect.height - menulabelRect.height; // const menuScaleFactor = menulabelRect.height / menuboxRect.height; // menubox.style.transform = `scale(1, ${menuScaleFactor})`; // menucontent.style.transform = `scale(1, 0)`; // menulabel.style.transform = `scale(1, ${1 / menuScaleFactor})` let timer = null; let currentItem = 0; const debouncedFn = (fn) => { timer && clearTimeout(timer); timer = setTimeout(fn, 250); } const documentAnimateHeight = (e) => { if (e.target === menubox || menubox.contains(e.target)) { e.stopPropagation(); return; } debouncedFn(() => { animateHeight(true); }); }; document.addEventListener('click', documentAnimateHeight); function animateHeight (collapsing, done) { let i = 0; function __animate () { // const scale = (collapsing ? frames - (i++) : i++) / frames; // const height = menulabelRect.height + (scale * slideHeight); const factor = Math.pow((i++) / frames - 1, 3) + 1; const height = menulabelRect.height + (collapsing ? 1 - factor : factor) * slideHeight; menubox.style.maxHeight = `${height}px`; if (i <= frames) { requestAnimationFrame(__animate); } else { if (collapsing) { const transitionEnded = () => { menubox.removeEventListener('transitionend', transitionEnded); document.removeEventListener('click', documentAnimateHeight); (typeof done === 'function') && done(); } menubox.classList.add('menubox--collapsed'); menubox.addEventListener('transitionend', transitionEnded, false); } else { menuchecks.item(currentItem = 0).focus(); (typeof done === 'function') && done(); } timer && clearTimeout(timer); timer = null; } } if (collapsing) { requestAnimationFrame(__animate); } else { const transitionEnded = () => { menubox.removeEventListener('transitionend', transitionEnded); requestAnimationFrame(__animate); } menubox.classList.remove('menubox--collapsed'); menubox.addEventListener('transitionend', transitionEnded, false); document.addEventListener('click', documentAnimateHeight); } } menubox.addEventListener('focus', () => { debouncedFn(() => { menubox.classList.contains('menubox--collapsed') && animateHeight(false, () => { menubox.blur(); menubox.setAttribute('tabIndex', -1); }); }); }); menubox.addEventListener('keydown', (e) => { switch (e.key) { case 'Down': case 'ArrowDown': { menuchecks.item(++currentItem === menuchecks.length ? (currentItem = 0) : currentItem).focus(); break; } case 'Up': case 'ArrowUp': { menuchecks.item(--currentItem < 0 ? (currentItem = menuchecks.length - 1) : currentItem).focus(); break; } case 'Enter': { menuchecks.item(currentItem).click(); break; } case 'Tab': case 'Escape': { debouncedFn(() => { !menubox.classList.contains('menubox--collapsed') && animateHeight(true, () => { // menubox.blur(); menubox.setAttribute('tabIndex', 0); }); }); break; } } }); menulabel.addEventListener('click', () => { debouncedFn(() => { animateHeight(!menubox.classList.contains('menubox--collapsed')); }); }); menuchecks.forEach((checkbox, index) => { checkbox.setAttribute('tabindex', -1); checkbox.addEventListener('change', function() { currentItem = index; if (!this.checked) { const checker = this.closest('label') .querySelector('.menubox__option-toggle-check'); const animationEnded = () => { checker.classList.remove('unchecking'); checker.removeEventListener('animationend', animationEnded); }; checker.classList.add('unchecking'); checker.addEventListener('animationend', animationEnded, false); } }, false); });
粒子
时间
文字
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号