仿京东左侧菜单 hover效果-简易demo

简单描述: 用到的知识点 css 中的绝对定位 以及 Js 中的事件冒泡(或事件委托)

1   .cont{display:inline-block;width:200px;height:200px;border:1px solid red;position:absolute;left:150px;top:2px;display:none;}
 1 <div style="border:1px solid green;margin:30px auto;width:150px;" id="menu">
 2
 3             <div class="item" id="div1" style="position:relative;">
 4                 <span style="display:inline-block;background: #abcdef;width:150px;height:50px;cursor:pointer;">123</span>
 5                 <span id="span1"  class="cont">
 6                      hello1111111
 7                      hello1111111
 8                      hello1111111
 9                      hello1111111
10                      hello1111111
11                 </span>
12             </div>
13
14             <div id="div2" class="item" style="position:relative;">
15                 <span style="display:inline-block;background: red;width:150px;height:50px;cursor:pointer;">123</span>
16                 <span class="cont">hello222222</span>
17             </div>
18
19             <div id="div3" class="item" style="position:relative;">
20                 <span style="display:inline-block;background: green;width:150px;height:50px;cursor:pointer;">123</span>
21                 <span class="cont">hello333333</span>
22             </div>
23
24          </div>
 1  window.onload = function(){
 2              var oSpan1 = document.getElementById("span1");
 3              var oMenu = document.getElementById("menu");
 4              var oSMenu = oMenu.childNodes;
 5
 6              for(var n=oSMenu.length-1; n>=0; n--){
 7                   if(oSMenu[n].className == "item"){
 8                       oSMenu[n].onmouseover = function(evt){
 9                             var target = oTargetByClass._get_target_child(this.childNodes, "cont");
10                             target.style.display = "block";
11                       }
12
13                        oSMenu[n].onmouseout = function(evt){
14                             var target = oTargetByClass._get_target_child(this.childNodes, "cont");
15                             target.style.display = "none";
16                      }
17                   }
18              }
19
20              var oTargetByClass = {
21
22                  _get_target_child: function(childNodes, child_class){
23                     for(var i = childNodes.length-1; i>=0; i--){
24                         if(childNodes[i].className == child_class){
25                              return childNodes[i];
26                         }
27                     }
28                  }
29              }
30          }
时间: 2024-08-05 11:09:42

仿京东左侧菜单 hover效果-简易demo的相关文章

竖向导航-仿京东左侧导航大类效果

完整代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Con

iOS仿京东分类菜单之UICollectionView内容

 iOS仿京东分类菜单之UICollectionView内容 在 上<iOS仿京东分类菜单实例实现>已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果,本文涉及到的主要是UICollectionView的知识内容,左边列表的实现见上一篇文章,先看实现的效果图: 一:实体的创建 1.1分组实体的创建(tagID跟左边表格进行关联,roomArray是存放房间的数组,也就是单元格的集合) #import <Foundation/Foundation.h>

Ionic 左侧菜单(登录主页详情demo)

1.项目结构 2.截图效果展示        3.主要js 代码 1 $stateProvider 2 .state('app', { 3 url: "/app", 4 abstract: true, 5 templateUrl: "templates/menu.html", 6 controller: 'MenuCtrl' 7 }) 8 //用户 9 .state('login', { 10 url: '/login', 11 templateUrl: 'temp

iOS仿京东分类菜单实例实现

在APP开发过程中此功能还是比较常见的模块,左边为菜单展示,右边为菜单下数据的展示,选择不同的菜单右边的数据源进行更新,此实例主要运用到UITableView,UICollectionView,OC谓词一些知识,结合Masonry进行布局:实现的效果如下: 涉及的知识点: 1:UITableView的运用,包含选中与非选中行不同展示,默认行分隔线的色彩跟与左边距离的调整,自动滚动到最顶端的实现等 2:UICollectionView的运用,包含单元格的加载,及重用时遇到的错乱问题,记录滚动位置的

DIV+CSS实现仿京东商城导航条效果

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv=&quo

Android Studio 使用ViewPager + Fragment实现滑动菜单Tab效果 --简易版

描述: 之前有做过一个记账本APP,拿来练手的,做的很简单,是用Eclipse开发的: 最近想把这个APP重新完善一下,添加了一些新的功能,并选用Android Studio来开发: APP已经完善了一部分,现在就想把已经做好的功能整理一下,记录下来. 效果图: 可以手动滑动菜单 也可以通过点击头部菜单进行切换           具体实现的代码: 前台代码(activity_main.xml): 1 <?xml version="1.0" encoding="utf-

仿京东商城左侧的一个导航条特效

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Typ

jquery实现左侧菜单 效果

html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>左侧菜单</title> <script type="text/javascript" src="js/jquery-3.0.0.min.js" ></script> <script type="text

一款jQuery插件+CSS打造的左侧菜单效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-