最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
js实现带三角符的手风琴效果
时间:2017-05-15 编辑:简简单单 来源:一聚教程网
效果图:
图(1)初始图
图(2)点击展开图
代码如下:
代码如下 | 复制代码 |
*{ margin: 0; padding: 0; } li{ list-style: none; } #list{ width: 240px; border: 1px solid #666; margin: 20px auto; } #list .lis{ } #list h2{ height: 30px; line-height: 30px; overflow: hidden; background: lightsalmon; color: #f1f1f1; } #list h2.active{ background: pink; height: 30px; line-height: 30px; overflow: hidden; color: #666; } #list h2.active div{ display: inline-block; width: 0; height: 0; border-left: 8px solid transparent; border-top: 12px solid #666; border-right:8px solid transparent; border-bottom:2px solid transparent; margin-right: 4px; } #list h2 div{ display: inline-block; width: 0; height: 0; border-left: 12px solid #f1f1f1; border-right: 6px solid transparent; border-bottom: 9px solid transparent; border-top:9px solid transparent; /*margin-right: 3px;*/ } #list .lis ul{ display: none; } #list .lis ul li{ line-height: 24px; border-bottom: 1px solid #666; text-indent: 15px; } #list .lis ul li.hover{ background: lightgreen; color: #F8F8F8; } #list .lis ul li:first-of-type{ border-top: 1px solid #ccc; } #list .lis:last-of-type ul li:last-of-type{ border-bottom:none; }
window.onload=function(){ var oUl=document.getElementById('list'); var aH2=oUl.getElementsByTagName('h2'); var aUl=oUl.getElementsByTagName('ul'); var h2Len=aH2.length; var aLi=null; var arrLi=[]; var aUlLen=aUl.length; for(var i=0;i aH2[i].index=i; aH2[i].onclick=function(){ if(this.className=='') { aUl[this.index].style.display='block'; this.className='active'; } else{ aUl[this.index].style.display='none'; this.className=''; } } } for(vari=0;i aLi=aUl[i].getElementsByTagName('li'); for(varj=0;j arrLi.push(aLi[j]); } } for(vari=0;i arrLi[i].onclick=function(){ for(vari=0;i arrLi[i].className=''; } this.className='hover'; } } }
高中同学
初中同学
|
相关文章
- js实现音乐播放器代码展示 10-12
- js实现图片查看器代码展示 10-12
- JS中switch的四种写法介绍 10-12
- js实现新闻轮播效果教程 10-11
- JS实现简单的图片切换功能教程 10-11
- js实现下拉刷新和上拉加载解析 09-28