javascript仿qq界面的折叠菜单实现代码
时间:2024-06-12 17:12:49
最近一直在研究网页特效,看到qq界面的折叠菜单,于是冒出个想法,自己写一个类似的,上网查了一下,发现已经有不少类似的菜单效果,不管那么多,先写着再说吧.
以下是html结构:
<div id="a"><div id="h1">sdfds</div><div id="b1">dsfdsfsdfsd</div><div id="h2">dsf</div><div id="b2">dsfdsfsdf</div>.......................</div>
id为a里的便是你要添加的菜单的标题和内容.
下面是javascript代码:
sx.activex.packmenu={
create:function(t){
var a=document.createElement("div");
var _t=t;
a.style.height="300px";
a.style.width="150px";
a.style.border="1px red solid";
a.style.overflow="hidden";
for(var i=0;i<t.length;i++){
var h=document.createElement("div");
var b=document.createElement("div");;
h.style.backgroundColor="blue";
h.style.height="10%";
b.style.padding="5px";
b.style.textAlign="center";
b.style.border="1px green solid";
h.innerHTML=t[i][0];
b.innerHTML=t[i][1];
b.style.overflow="hidden";
b.style.height="0px";
b.style.display="none";
h.onclick=function(){
if(this.nextSibling.style.display=="none"){
this.nextSibling.style.height="1px";
this.nextSibling.style.display="block";
this.h=window.setInterval(function(t,t1){
return function(){
if(!t1) return;
//alert(t.nextSibling.offsetHeight);
if(parseInt(t.nextSibling.style.height)<100-_t.length*parseInt(a.all[0].style.height)-3){
t.nextSibling.style.height=parseInt(t.nextSibling.style.height)+3+"%";
t1.style.height=parseInt(t1.style.height)-3+"%";
}
else{
t.nextSibling.style.height=100-_t.length*parseInt(a.all[0].style.height)+"%";;
t1.style.display="none";
t1.style.height="0px";
window.clearInterval(t.h);
}
}
}(this,(function(){
for(var ii=0;ii<a.all.length;ii++){
if(parseInt(a.all[ii].style.height)>10)
return a.all[ii];
}
})()),10);
}
else{
if(this!=this.parentNode.firstChild){
this.previousSibling.style.height="1px";
this.previousSibling.style.display="block";
}
else{
this.parentNode.lastChild.style.display="block";
this.parentNode.lastChild.style.height="1px";
}
this.h=window.setInterval(function(t,t1){
return function(){
if(!t1) return;
if(parseInt(t.nextSibling.style.height)>3){
if(t!=t.parentNode.firstChild)
t.previousSibling.style.height=parseInt(t.previousSibling.style.height)+3+"%";
else
t.parentNode.lastChild.style.height=parseInt(t.parentNode.lastChild.style.height)+3+"%";
t1.style.height=parseInt(t1.style.height)-3+"%";
}
else{
if(t!=t.parentNode.firstChild)
t.previousSibling.style.height=100-_t.length*parseInt(a.all[0].style.height)+"%";
else
t.parentNode.lastChild.style.height=100-_t.length*parseInt(a.all[0].style.height)+"%";
t.nextSibling.style.display="none";
t.nextSibling.style.height="0px";
window.clearInterval(t.h);
}
}
}(this,(function(){
for(var ii=0;ii<a.all.length;ii++){
if(parseInt(a.all[ii].style.height)>10)
return a.all[ii];
}
})()),1);
}
}
a.appendChild(h);
a.appendChild(b);
a.all[1].style.display="block";
a.all[1].style.height=100-t.length*parseInt(a.all[0].style.height)+"%";
}
return a;
}
}
入口参数t是你要传递的二维数组,以一个标题加内容为一个数组项的形式:
下面是调用代码:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<script src="kongjian.js" ></script>
<script>
var a=sx.activex.packmenu.create([["asd","sadsadas"],["sd","sadsaas"],["w","waedqwdq"],["e","efwefw"]]);
//a.contentEditable=true;
document.body.appendChild(a);
</script>
</body>
</html>
搞定,有兴趣的朋友可以看下效果.
标签:折叠菜单,仿qq界面
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
解决python3插入mysql时内容带有引号的问题
2024-01-24 13:34:09
Python实现简单的HttpServer服务器示例
2021-02-07 21:29:35
Python使用turtle模块绘制爱心图案
2022-07-31 06:46:26
![](https://img.aspxhome.com/file/2023/9/107499_0s.jpg)
教你怎么用Python实现多路径迷宫
2022-03-11 15:07:52
![](https://img.aspxhome.com/file/2023/4/112784_0s.png)
艺术和设计之间的差别
2010-11-17 19:28:00
![](https://img.aspxhome.com/file/UploadPic/201011/17/01-13s.jpg)
MySQL中存储的数据查询的时候如何区分大小写
2024-01-21 12:01:27
![](https://img.aspxhome.com/file/2023/9/124089_0s.png)
python正则表达式及使用正则表达式的例子
2021-07-28 20:15:41
anaconda创建、查看、激活与删除虚拟环境指令总结
2023-04-09 13:01:23
![](https://img.aspxhome.com/file/2023/1/134601_0s.jpg)
176万!GPT-4发布详解如何查看OpenAI的下载量
2021-11-26 22:02:51
Go并发编程中sync/errGroup的使用
2024-02-05 04:40:56
Python中的单行、多行、中文注释方法
2022-03-21 21:56:38
![](https://img.aspxhome.com/file/2023/8/78638_0s.jpg)
使用SQL语句去掉重复的记录【两种方法】
2024-01-18 16:55:59
复制粘贴功能的Python程序
2023-10-02 18:46:51
PHP PDOStatement::fetchAll讲解
2023-06-14 15:54:26
python使用__slots__让你的代码更加节省内存
2023-03-15 06:33:57
![](https://img.aspxhome.com/file/2023/5/77805_0s.jpg)
python-yml文件读写与xml文件读写
2022-06-16 06:43:50
![](https://img.aspxhome.com/file/2023/9/67919_0s.png)
设计能力决定权力
2009-06-16 14:48:00
![](https://img.aspxhome.com/file/UploadPic/20096/16/d-68s.jpg)
Python version 2.7 required, which was not found in the registry
2021-06-02 14:57:13
![](https://img.aspxhome.com/file/2023/9/67929_0s.png)
JavaScript实现模仿桌面窗口的方法
2024-04-19 10:16:56
Ubuntu18.04下python版本完美切换的解决方法
2021-08-22 11:24:19
![](https://img.aspxhome.com/file/2023/9/112129_0s.jpg)