| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1567 人关注过本帖
标题:请高手帮忙看下JS代码
只看楼主 加入收藏
季孙意如
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-12-8
收藏
 问题点数:0 回复次数:0 
请高手帮忙看下JS代码
要实现的功能是点击出现二级菜单 再点击收回 js总报错 麻烦帮忙看下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
padding: 0px;
margin: 0px;
}
body{
background-color: rgb(45,44,65);
}
ul{
position: absolute;
left:50%;
top:200px;
margin-left: -180px;
border-radius: 8px;
overflow: hidden;
}
li{
list-style: none;
height:50px;
background-color: white;
width:360px;
}
.hidden{
overflow: hidden;
}
div{
width:310px;
height:49px;
padding-left: 50px;
line-height:49px;
border-bottom: 1px solid rgb(204,204,204);
}
a{
display: block;
text-decoration: none;
width:310px;
line-height:42px;
padding-left: 50px;
color:#d9d9d9;
background-color: rgb(68,67,89);
border-bottom: 1px solid rgb(75,74,94);
}
a:hover{
background-color: rgb(182,59,77);
}
</style>
</head>
<body>
<ul id='wrap'>
<li class='hidden'>
<div>Diseño web</div>
<a href='#'>Photoshop</a>
<a href='#'>HTML</a>
<a href='#'>CSS</a>
<a href='#'>Maquetacion web</a>
</li>
<li class='hidden'>
<div>Diseño web</div>
<a href='#'>Photoshop</a>
<a href='#'>HTML</a>
<a href='#'>CSS</a>
<a href='#'>Maquetacion web</a>
</li>
<li class='hidden'>
<div>Diseño web</div>
<a href='#'>Photoshop</a>
<a href='#'>HTML</a>
<a href='#'>CSS</a>
<a href='#'>Maquetacion web</a>
</li>
<li class='hidden'>
<div>Diseño web</div>
<a href='#'>Photoshop</a>
<a href='#'>HTML</a>
<a href='#'>CSS</a>
<a href='#'>Maquetacion web</a>
</li>
</ul>
</body>
</html>
<script type="text/javascript">
var object={
speed:3,
timer:null,
clickfun:function(id){
var wrap=document.getElementById(id);
var aDiv=wrap.getElementsByTagName('div');
var oA=wrap.getElementsByTagName('a')[0];
for(var i=0;i<aDiv.length;i++){
/*var minH=aDiv[i].offsetHeight;
var maxH=oA.offsetHeight*4+minH-1;*/
aDiv[i].onclick=function(){
object.time(this.parentNode);
alert(this.parentNode);
}
}
},
time:function(element){
this.timer=setInterval(function(){
element.className=='hidden'?this.open(element):this.close(element);
},5)
},
open:function(element){
var minH=aDiv[i].offsetHeight;
var maxH=oA.offsetHeight*4+minH-1;
var nowH=element.offsetHeight;
if(nowH<maxH){
element.style.height=nowH+this.speed+'px';
}else{
clearInterval(this.timer);
element.style.height=maxH;
this.setClassName(element,'');
}
},
close:function(element){
var minH=aDiv[i].offsetHeight;
var nowH=element.offsetHeight;
if(nowH>minH){
element.style.height=nowH-this.speed+'px';
}else{
clearInterval(this.timer);
element.style.height=minH;
this.setClassName(element,'hidden');
}
},
setClassName:function(obj,className){
obj.className=className;
}
}
object.clickfun('wrap');
</script>
搜索更多相关主题的帖子: div href var element this 
2017-12-08 18:47
快速回复:请高手帮忙看下JS代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022811 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved