首页 技术 正文
技术 2022年11月7日
0 收藏 784 点赞 975 浏览 1524 个字

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

   .cont{display:inline-block;width:200px;height:200px;border:1px solid red;position:absolute;left:150px;top:2px;display:none;}
 <div style="border:1px solid green;margin:30px auto;width:150px;" id="menu">             <div class="item" id="div1" style="position:relative;">
<span style="display:inline-block;background: #abcdef;width:150px;height:50px;cursor:pointer;">123</span>
<span id="span1" class="cont">
hello1111111
hello1111111
hello1111111
hello1111111
hello1111111
</span>
</div> <div id="div2" class="item" style="position:relative;">
<span style="display:inline-block;background: red;width:150px;height:50px;cursor:pointer;">123</span>
<span class="cont">hello222222</span>
</div> <div id="div3" class="item" style="position:relative;">
<span style="display:inline-block;background: green;width:150px;height:50px;cursor:pointer;">123</span>
<span class="cont">hello333333</span>
</div> </div>
  window.onload = function(){
var oSpan1 = document.getElementById("span1");
var oMenu = document.getElementById("menu");
var oSMenu = oMenu.childNodes; for(var n=oSMenu.length-1; n>=0; n--){
if(oSMenu[n].className == "item"){
oSMenu[n].onmouseover = function(evt){
var target = oTargetByClass._get_target_child(this.childNodes, "cont");
target.style.display = "block";
} oSMenu[n].onmouseout = function(evt){
var target = oTargetByClass._get_target_child(this.childNodes, "cont");
target.style.display = "none";
}
}
} var oTargetByClass = { _get_target_child: function(childNodes, child_class){
for(var i = childNodes.length-1; i>=0; i--){
if(childNodes[i].className == child_class){
return childNodes[i];
}
}
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,996
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,510
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,353
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,137
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848