温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css3和jquery如何实现可折叠导航菜单适合放在手机网页的导航菜单

发布时间:2021-06-25 09:46:55 阅读:181 作者:小新 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍了css3和jquery如何实现可折叠导航菜单适合放在手机网页的导航菜单,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

效果图如下:
css3和jquery如何实现可折叠导航菜单适合放在手机网页的导航菜单 
这个实例由css3和依赖于jquery插件。下面是实现代码
html代码:

<nav class="nav" role="navigation" > 
<ul class="nav-items"> 
<li><a target=_blank href="http://www.w2bc.com">Home</a></li> 
<li><a target=_blank href="http://www.w2bc.com">About</a></li> 
<li><a target=_blank href="http://www.w2bc.com">Clients</a></li> 
<li><a target=_blank href="http://www.w2bc.com">Contact Us</a></li> 
</ul> 
</nav> 
<header > 
<button class="menu-button-target active" data-ic-class="button-trigger"> 
<span class="menu-button"></span> 
</button> 
Example Header 
</header> 
<section> 
<article> 
</article> 
<article> 
</article> 
<article> 
</article> 
<article> 
</article> 
<article> 
</article> 
</section>


css3代码:

*
{
box-sizing: border-box;
}
body
{
font-family"HelveticaNeue-Light" , "Helvetica Neue Light" , "Helvetica Neue" , Helvetica, Arial, "Lucida Grande" , sans-serif;
font-weight300;
}
nav
{
position: fixed;
-webkit-transformtranslate3d(000);
left0;
transition: all 0.4s ease;
width100%;
background#34495e;
height0;
overflow: hidden;
transition-delay0.25s;
}
.active nav
{
transition-delay0s;
}
nav ul
{
width95%;
margin0 auto;
}
nav ul li
{
padding5px;
border-bottom1px solid white;
}
nav ul li:nth-child(1a
{
transition-delay0.1s;
}
nav ul li:nth-child(2a
{
transition-delay0.15s;
}
nav ul li:nth-child(3a
{
transition-delay0.2s;
}
nav ul li:nth-child(4a
{
transition-delay0.25s;
}
nav ul li:last-child
{
border: none;
}
nav ul li a
{
transition: all 0.2s cubic-bezier(0.4550.030.5150.955);
position: relative;
display: block;
text-decoration: none;
color: white;
font-size18px;
padding10px;
-webkit-transformtranslate3d(100px00);
opacity0;
}
.active nav ul li a
{
-webkit-transformtranslateX(0);
opacity1;
}
header
{
transition: all 0.4s ease;
-webkit-transformtranslate3d(000);
left0;
width100%;
position: fixed;
background#27ae60;
color: white;
padding20px;
text-align: center;
font-size20px;
transition-delay0.25s;
}
.active header
{
transition-delay: .08s;
}
section
{
background#f5f5f5;
padding-top80px;
}
article
{
background: white;
height500px;
width95%;
border-radius3px;
margin0 auto 20px auto;
border1px solid #e4e4e4;
}
.menu-button-target
{
background: transparent;
border: none;
outline: none;
cursor: pointer;
position: absolute;
z-index200;
left10px;
height50px;
top50%;
margin-top: -23px;
webkit-tap-highlight-colorrgba(0000);
}
.menu-button-target.active .menu-button
{
transition: background .2s ease;
background-color: transparent;
}
.menu-button-target.active .menu-button:before.menu-button-target.active .menu-button:after
{
transition: top .3s ease, -webkit-transform .3s .2s ease;
}
.menu-button-target.active .menu-button:before
{
top0;
-webkit-transformrotate(45deg);
}
.menu-button-target.active .menu-button:after
{
top0;
-webkit-transformrotate(-45deg);
}
.menu-button
{
position: relative;
top50%;
left0;
display: block;
width40px;
height4px;
margin-top: -2px;
background-color: white;
border-radius10px;
transition: background .2s .2s;
}
.menu-button:before.menu-button:after
{
content"";
display: block;
position: absolute;
width100%;
height100%;
left0;
background-color: white;
transition: top .3s .2s ease, -webkit-transform .3s ease;
border-radius10px;
-webkit-transform-origin50% 50%;
}
.menu-button:before
{
top: -10px;
-webkit-transformrotate(0deg);
}
.menu-button:after
{
top10px;
-webkit-transformrotate(0deg);
}

js代码:

var $menuTrigger = $('[data-ic-class="button-trigger"]'),
$menuOverlay = $('[data-ic-class="overlay"]'),
$menuItem = $('.menu-item'),
activeClass = 'active',
$nav = $('nav'),
$navULHeight = $('.nav-items').outerHeight(),
navOpen = false,
$header = $('header');
var isTouch = false;
if ($('html').hasClass('touch')) {
isTouch = true;
}
function menuFunction() {
$menuTrigger.toggleClass(activeClass);
if (!navOpen) {
$nav.height($navULHeight);
navOpen = true;
$('body').addClass('active');
$header.css('transform''translate3d(0, ' + $navULHeight + 'px, 0)');
} else {
$nav.height(0);
$header.css('transform''translate3d(0, 0, 0)');
navOpen = false;
$('body').removeClass('active');
}
}
if (isTouch) {
$menuTrigger.on('touchstart', function () {
menuFunction();
});
}
if (!isTouch) {
$menuTrigger.on('click', function () {
menuFunction();
});
}

感谢你能够认真阅读完这篇文章,希望小编分享的“css3和jquery如何实现可折叠导航菜单适合放在手机网页的导航菜单”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://www.jb51.net/css/213001.html

AI

开发者交流群×