js实现仿京东2级菜单效果(带延时功能)
网络编程 2021-07-04 21:48www.168986.cn编程入门
这篇文章主要介绍了js实现仿京东2级菜单效果,涉及jquery鼠标事件动态操作页面元素属性及延时显示的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了jquery实现仿京东2级菜单效果。分享给大家供大家参考。具体如下
这里介绍js实现仿京东2级菜单效果代码,带有延时功能,操作上更加舒适自然。
先来看看运行效果截图
在线演示地址如下
具体代码如下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>仿京东网站的2级菜单导航</title> <style type="text/css"> ul{margin:0;padding:0;list-style-type:none;} a{ text-decoration:none;} .mold_open_hover,.mold_open{background-image:url();background-repeat:none;display:inline-block;width:10px;height:6px;margin-left:10px;position:relative;:-2px;} .mold_open{background-position:0 -6px;} .mold_open_hover{background-position:0 0;} .mod-menu{position:relative;z-index:1000;left:-1px;margin-left:100px;} h1{margin-left:100px;} .menu-cont-list a:hover{text-decoration:underline;} .mod-menu .menu-item{width:220px;border-:solid 1px #d59bb2;border-bottom:solid 2px #d59bb2;position:relative;z-index:22;} .mod-menu .menu-item li{height:47px;line-height:47px;background:#feebf3;border-:solid 1px #f0bfd3;} .mod-menu .menu-item li.mouse-bg{background:url() no-repeat #fff;position:relative;z-index:22;margin-right:-4px;} .mod-menu .menu-item a{color:#c81d61;font-size:16px;padding-left:33px;display:block;height:45px;border-:solid 1px #f1f2f7;} .mod-menu .menu-item a:hover{ text-decoration:none;} .mod-menu .menu-cont{position:absolute;left:220px;:1px;background:#fff;width:573px;border:solid 1px #F0BFD3;box-shadow:2px 0 10px rgba(210,33,103,0.25);z-index:20;} .mod-menu .menu-cont-list{padding:0 30px;} .mod-menu .menu-cont-list li{border-bottom:dotted 1px #f0bfd3;padding:10px 0;} .mod-menu .menu-cont-list li:last-child{border-bottom:none;} .mod-menu .menu-cont-list h3{font-size:14px;font-weight:700;} .mod-menu .menu-cont-list h3 a{color:#222;} .mod-menu .menu-list-link a{color:#666;line-height:24px;} .mod-menu .menu-list-link .long-string{color:#c;font-size:12px;padding:0 10px;} </style> <script src="jquery-1.6.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var l; var t; var menuItem; $(document).ready(menu_init); function menu_init() { var mod_menu=$(".mod-menu");//导航模块区 menu();//执行展开二级菜单函 //setTimeout(menu(),1000) } var menu=function() { menuItem=$(".menu-item li");//选择导航列表 menuItem.each(menu_each);/导航菜单菜单/ menuItem.mouseleave(menu1_leave);/导航菜单菜单/ $(".mod-menu").mouseleave(menu2_mouse_leave); }//展开二级菜单 var menu_each=function() { var _index=$(this).index();//获取当前选择菜单列表的索引 $(this).mouseenter(menu_mouse_enter); } var menu_mouse_enter=function() { l = $(this);//获取当前鼠标滑过的列表的顶部坐标 t=setTimeout("menu_mouse_enter_show()", 300) } function menu_mouse_enter_show() { // alert(y1); var y = l.position().+1;//获取当前鼠标滑过的列表的顶部坐标 $(".menu-cont").show(); $(".menu-cont").css("",y);//需要显示的对应索引内容 l.addClass("mouse-bg").siblings().removeClass("mouse-bg"); $(".menu-cont>div").eq(_index).show().siblings().hide(); } var menu1_leave=function() { clearTimeout(t); } var menu2_mouse_leave=function() { $(".menu-cont").hide(); menuItem.removeClass("mouse-bg"); } </script> </head> <body> <h1>简单的2级菜单导航</h1> <div class="mod-menu f-l"> <div id="column-left"> <ul class="menu-item"> <li class=""><a href="#">Wedding</a></li> <li class=""><a href="#">Women's Shoes</a></li> <li class=""><a href="#">Aessories</a></li> <li class=""><a href="#">Beauty & Health</a></li> </ul><!--一级菜单列表--> <div class="menu-cont hide" style="display: none; : 241px;"> <div class="menu-cont-list" style="display: none;"> <ul> <li> <h3><a href="#">Wedding Dresses</a></h3> <div class="menu-list-link"></div> </li> <li> <h3><a href="#">Bridesmaid Dresses</a></h3> <div class="menu-list-link"></div> </li> <li> <h3><a href="#">Wedding Party Dresses</a></h3> <div class="menu-list-link"> <a title="" href="#">Mother of the Brides Dresses</a> <span class="long-string">|</span> <a title="" href="#">Flower Girl Dresses</a> <span class="long-string">|</span> <a title="" href="#">Wedding Guest Dresses</a> </div> </li> <li> <h3><a href="#">Wedding Aessories</a></h3> <div class="menu-list-link"> <a title="" #">Fabric Swatch</a> <span class="long-string">|</span> <a title="" href="#">Bridal Lingerie</a> <span class="long-string">|</span> <a title="" href="#">Wedding Flowers</a> <span class="long-string">|</span> <a title="" href="#">Wedding Petticoats</a> </div> </li> </ul> </div> <div class="menu-cont-list" style="display: none;"> <ul> <li> <h3><a href="#">Prom Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Military Ball Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Evening Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Cocktail Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Ball Gowns</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Homeing Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Little Black Dresses </a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Quinceanera Dresses</a></h3> <div class="menu-list-link"> </div> </li> </ul> </div> <div class="menu-cont-list" style="display: none;"> <ul> <li> <h3><a href="#">Dresses</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Clubwear</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Leggings</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Lingeries</a></h3> <div class="menu-list-link"> <a title="" #">Bras</a> <span class="long-string">|</span> <a title="" href="#">Babydolls</a> <span class="long-string">|</span> <a title="" href="#">Panties</a> <span class="long-string">|</span> <a title="" href="#">Hosiery</a> </div> </li> <li> <h3><a href="#">Swimwear</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Activewear</a></h3> <div class="menu-list-link"> </div> </li> </ul> </div> <div class="menu-cont-list" style="display: none;"> <ul> <li> <h3><a href="#">Heels</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Pumps</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Boots</a></h3> <div class="menu-list-link"> </div> </li> </ul> </div> <div class="menu-cont-list" style="display: none;"> <ul> <li> <h3><a href="#">Evening Bags</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Hats & Scarves</a></h3> <div class="menu-list-link"> <a title="" href="#">Womens Hats</a> <span class="long-string">|</span> <a title="" href="#">Womens Scarves</a> </div> </li> <li> <h3><a href="#">Jewelry</a></h3> <div class="menu-list-link"> <a title="" href="#">Earrings</a> <span class="long-string">|</span> <a title="" href="#">Necklaces</a> <span class="long-string">|</span> <a title="" href="#">Rings</a> </div> </li> <li> <h3><a href="#">Watches</a></h3> <div class="menu-list-link"> </div> </li> </ul> </div> <div class="menu-cont-list" style="display: block;"> <ul> <li> <h3><a href="#">Wigs & Hair extensions</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Fascinators</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Makeup Tools</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Spas & Massagers</a></h3> <div class="menu-list-link"> </div> </li> <li> <h3><a href="#">Health & Fitness</a></h3> <div class="menu-list-link"> </div> </li> </ul> </div> </div> </div><!--二级菜单内容--> </div> 若提示有错误,请刷新网页 </body> </html>
希望本文所述对大家的jquery程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程