首页 / JQUERY / 使用jquery实现的自适应导航
使用jquery实现的自适应导航
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用jquery实现的自适应导航,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3863字,纯文字阅读大概需要6分钟。
内容图文
话不多说,直接晒代码
1 < div class ="headering" > 2 < div class ="header-top" > 3 < div class ="btn-header" > 4 < a href ="#" >网站logo</a> 5<button id="btn"> 6<span></span> 7<span></span> 8<span></span> 9</button>10</div>11<div class="nav-tab">12<div class="nav">13<ul>14<li><a href="#">首页</a></li>15<li><a href="#">公司简介</a></li>16<li><a href="#">新闻中心</a></li>17<li><a href="#">产品展示</a></li>18<li><a href="#">工程案例</a></li>19<li><a href="#">联系我们</a></li>20</ul>21</div>22<div class="about"><a href="#">tel:12345678901</a></div>23</div>24</div>25</div>
css代码(nav.css)
{margin: 0px;padding:0px;color:#9D9D9D;font-size: 0;} html body{width: 100%;} a{text-decoration: none;font-size: 14px;} li{list-style: none;} /* 头部 */ .headering{ width: 100%; height: 50px; display: flex; justify-content: center; align-items: center; line-height: 48px; background-color: #222; border-bottom: 1px solid #000; position: fixed; z-index: 3; } .header-top{position: relative;} .header-top{ width: 1170px;margin: 0 auto;padding-left: 22px;padding-right: 22px;box-sizing: border-box;} .header-top .btn-header{width: 100%;position: relative;} .btn-header a{font-size: 20px;font-weight: 400;} .btn-header a:hover, .nav ul li a:hover, .about a:hover{color: #fff;} .btn-header button, .about{float: right;} .btn-header button{ background-color: transparent; border:1px solid #333; border-radius: 1px; padding: 9px 10px; margin: 8px 15px 0px 0; display: none; outline: none; } .btn-header button span{ display: block; width: 22px; height: 2px; background-color: #fff; border-radius: 1px; } .btn-header button span:not(:nth-of-type(1)){ margin-top: 4px; } .header-top .nav-tab{ position: absolute; top:2px; left: 200px; width: 80%; } .nav{ float: left; } .nav ul li{ float: left; font-size: 14px; } .nav ul li a{ padding: 0 15px; } .show{height:350px;transition: all 2s linear;visibility: visible;opacity: 0;} .hide{transition: all 2s linear;visibility: hidden;opacity: .6;}
css代码(app.css)响应式代码
@media screen and (min-width:992px) and (max-width:1200px){ *{ box-sizing: border-box; padding: 0px; margin: 0px; } .header-top,{ width: 970px; /* border:1px solid red; */ margin: 0 auto; padding: 0 22px; } .nav ul li:first-of-type{ display: none; } .about{ margin-right: 40px; } } @media screen and (min-width:768px) and (max-width:991px){ *{ box-sizing: border-box; padding: 0px; margin: 0px; } .header-top,{ width: 750px; /* border:1px solid red; */ margin: 0 auto; padding: 0 22px; } .header{ min-height: 40px; } .nav ul li:first-of-type, .btn-header a, .about{ display: none; } .header-top .nav-tab{ top:-25px; left: 15px; } } @media screen and (max-width:767px){ .btn-header button{ display: block; float: right; margin: 10px 0 0 0; } .header-top .nav-tab{ width: 100%; background-color: #222; left: 0px; top: 50px; padding-left: 10px; border-top: 1px solid #393939; display: none; border-top: 1px solid transparent; -webkit-box-shadow: inset 0 1px 0 rgba(255,255,255,.1); box-shadow: inset 0 1px 0 rgba(255,255,255,.1); } .about{ position: absolute; bottom: 11px; left: 25px; display: none; } .nav ul li{ clear: both; } .about2 div{ margin-bottom: 10px; } }
jq代码
先引入jq插件:<script src=‘https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js‘></script>
// 导航PC端和手机端的显示切换 $(window).resize(function () { myResize(); }); window.onload=function(){ $("#btn").click(function(){ $(".nav-tab").slideToggle(600); }) } function myResize(){ if($(window).width() >= 768){ $(".nav-tab").show(); }else{ $(".nav-tab").hide(); } }
原文:https://www.cnblogs.com/shine1234/p/12893557.html
内容总结
以上是互联网集市为您收集整理的使用jquery实现的自适应导航全部内容,希望文章能够帮你解决使用jquery实现的自适应导航所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。