鼠标移入侧边栏一级菜单后,二级菜单显示
来源:互联网 发布:线性代数中矩阵求模 编辑:程序博客网 时间:2024/04/30 05:36
就是简简单单的一个小功能,鼠标移入侧边栏的一级菜单后,相对应的二级菜单显示。
效果大概如图:
CSS:
<style> * { margin: 0; padding: 0; } .wrap { width: 150px; position: relative; margin: 10px 0 0 10px; background-color: #c0c0c0; } .wrapper { list-style: none; margin-left: 5px; height: 40px; line-height: 40px; cursor: pointer; position: relative; } .wrapper_a { text-decoration: none; color: #000000; } .wrap ul li a { display: inline-block; width: 100%; height: 100%; } .wrap ul li a:hover { color: #ffffff; } .details_wrap { width: 100px; height: 40px; line-height: 40px; background-color: #666666; position: absolute; left: 100%; top: 0; padding-left: 5px; list-style: none; display: none; } .details_wrap a { text-decoration: none; color: darkgrey; } .details_wrap a:hover { color: dimgray; }</style>
HTML:
<div class="wrap"> <ul> <li class="wrapper"> <a href="#" class="wrapper_a">居家</a> <ul> <li class="details_wrap"><a href="#" class="details">详情1</a></li> </ul> </li> <li class="wrapper"> <a href="#" class="wrapper_a">生活</a> <ul> <li class="details_wrap"><a href="#" class="details">详情2</a></li> </ul> </li> <li class="wrapper"> <a href="#" class="wrapper_a">购物</a> <ul> <li class="details_wrap"><a href="#" class="details">详情3</a></li> </ul> </li> <li class="wrapper"> <a href="#" class="wrapper_a">科普</a> <ul> <li class="details_wrap"><a href="#" class="details">详情4</a></li> </ul> </li> </ul></div>
JS:
<script src="../jquery-1.11.0.min.js"></script><script> $(document).ready(function(){ 方法一: $(".wrapper").mouseover(function () { $(".details_wrap",this).show(); }).mouseout(function () { $(".details_wrap",this).hide(); }); $(".details_wrap").mouseover(function () { $(".details_wrap",this).show(); }).mouseout(function () { $(".details_wrap",this).hide(); }) 方法二: $(".wrapper").mouseover(function () { $(this).find(".details_wrap").css('display','block'); }).mouseout(function () { $(this).find(".details_wrap").css('display','none'); }) })</script>
不知道为啥,方法二的格式有错误,请自行调整。
两只小菜鸟被这个搞了一下午,但依然存在很多疑问。比如,方法一中mouseover前为什么选择wrapper而不能是其他?
请指教啊。
另外,还有没有其他的方法?
不吝赐教啊。
阅读全文
0 0
- 鼠标移入侧边栏一级菜单后,二级菜单显示
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)
- JQuery中鼠标划过一级菜单,有二级菜单的就显示的处理
- 鼠标悬浮显示二级菜单
- 一级二级菜单slideToggle
- 鼠标移入显示一个菜单列表 移出隐藏
- 商城头部鼠标移入显示菜单选项 【jquery】
- 一级菜单hover进入二级菜单,二级菜单不消失
- 一级横菜单二级坚菜单
- JQuery.HoverDir库实现侧边栏二级菜单
- 网页左侧边栏二级菜单的学习
- 菜单鼠标移入移出切换图片
- 角色权限管理系统(二级菜单的显示、一级菜单管理)
- 侧边栏菜单
- Selenium笔记---鼠标悬停显示二级菜单 点击下拉列表
- 动态建立右键菜单(一级/二级/三级) 响应鼠标单击事件及修改项的内容
- JavaScript跳转菜单(一级,二级,三级)
- 侧边菜单
- iOS探索--IOS学习路线总结
- Python 爬虫入门 3 Selenium+Python
- 【友盟分享】部分手机出现第一次分享之后第二次无法分享
- 浅谈Hybrid技术的设计与实现
- 深入理解RunLoop
- 鼠标移入侧边栏一级菜单后,二级菜单显示
- log4j.properties详解与例子
- 笔记-NopCommerce系统架构分析-引擎和依赖管理IOC
- 链表的基本操作
- 父组件向子组件传递数据(vue.js)
- Android基础学习
- android Volley 源码分析
- GTS4.1 R1常见问题处理
- Spring(03)——依赖注入