Toggle navigation
在线编辑器
在线代码
文本比较
jQuery下载
前端库
在线手册
登录/注册
下载代码
html
css
js
分享到微信朋友圈
X
html
Home
Likes
Search
Profile
css
@import url("https://fonts.googleapis.com/css?family=Open+Sans:700"); * { box-sizing: border-box; margin: 0; padding: 0; } /* by default include the background of the option for the home navigation */ body { background: #5b37b7; color: #010101; /* center in the viewport */ min-height: 100vh; display: grid; place-items: center; font-family: "Open Sans", sans-serif; /* transition for the change in bg color */ transition: background 0.2s ease-out; } /* display the anchor link side by side */ nav { display: flex; background: #fff; /* considerable whitespace surrounding the navigation's items */ padding: 2rem 3.15rem; border-radius: 0 0 30px 30px; box-shadow: 0 1px 15px rgba(0, 0, 0, 0.1); } /* remove default style and slightly separate the anchor links from one another */ a { color: inherit; text-decoration: none; margin: 0 0.2rem; /* display the svg icon and span elements side by side, vertically aligned */ display: flex; align-items: center; /* include padding for the background applied on the active item */ padding: 0.75rem 1.25rem; border-radius: 30px; /* position relative for the pseudo element */ position: relative; /* custom properties for the colors picked up by the elements when clicked (and updated for each link in the script) */ --hover-bg: #5b37b720; --hover-c: #5b37b7; } /* include considerable negative margin to have the svg icon overlapping with the span element */ a svg { margin-right: -2.5rem; width: 28px; height: 28px; pointer-events: none; /* transition for the change in margin */ transition: margin 0.2s ease-out; } /* by default hide the span element */ a span { opacity: 0; visibility: hidden; font-size: 0.9rem; margin-left: 0.9rem; } /* include with a pseudo element relative to the anchor link a circle, with a fixed with and height */ a:before { position: absolute; content: ""; top: 50%; left: 0; width: 70px; height: 70px; border-radius: 50%; /* positioned to the left of the anchor link and scaled to 0 */ transform: translate(0%, -50%) scale(0); visibility: visible; opacity: 1; } /* when active */ /* specify the colors dictated by the custom properties */ a.active { background: var(--hover-bg); color: var(--hover-c); } /* using the color specified by the then updated custom property show the circle of the pseudo element increasing its size and highlighting it momentarily */ a.active:before { background: var(--hover-c); opacity: 0; visibility: hidden; transform: translate(0%, -50%) scale(2); /* transition only when the class is applied */ transition: all 0.4s ease-out; } /* remove the margin applied to the svg to make it overlay atop the anchor link */ a.active svg { margin-right: 0; } /* show the span element */ a.active span { visibility: visible; opacity: 1; transition: all 0.2s ease-out; } /* on smaller viewports show the navigation bar on the side, attached to the left of the screen */ @media (max-width: 500px) { nav { flex-direction: column; justify-self: start; border-radius: 0 30px 30px 0; padding: 2rem 1.15rem 2rem 0.75rem; } /* change the margin separating the anchor link elements now dividing the elements vertically */ nav a { margin: 0.5rem 0; } /* remove the negative margin from the svg elements, as the width is to be taken in full */ nav svg { margin: 0; } }
JavaScript
// array describing the options of the navigation elements // specifying the lower case option and the matching color const navigationOptions = [ { name: 'home', color: '#5B37B7' }, { name: 'likes', color: '#C9379D' }, { name: 'search', color: '#E6A919' }, { name: 'profile', color: '#1892A6' } ]; // target all anchor link elements const links = document.querySelectorAll('nav a'); // function called in response to a click event on the anchor link function handleClick(e) { // prevent the default behavior, but most importantly remove the class of .active from those elements with it e.preventDefault(); links.forEach(link => { if (link.classList.contains('active')) { link.classList.remove('active'); } }); // retrieve the option described the link element const name = this.textContent.trim().toLowerCase(); // find in the array the object with the matching name // store a reference to its color const { color } = navigationOptions.find(item => item.name === name); // retrieve the custom property for the --hover-c property, to make it so that the properties are updated only when necessary const style = window.getComputedStyle(this); const hoverColor = style.getPropertyValue('--hover-c'); // if the two don't match, update the custom property to show the hue with the text and the semi transparent background if (color !== hoverColor) { this.style.setProperty('--hover-bg', `${color}20`); this.style.setProperty('--hover-c', color); } // apply the class of active to animate the svg an show the span element this.classList.add('active'); // change the color of the background of the application to match document.querySelector('body').style.background = color; } // listen for a click event on each and every anchor link links.forEach(link => link.addEventListener('click', handleClick));
粒子
时间
文字
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号