js實現(xiàn)帶三角符的手風琴效果
更新時間:2017年03月01日 15:02:24 作者:marie0119
本文主要介紹了js實現(xiàn)帶三角符手風琴效果的實例。具有很好的參考價值,下面跟著小編一起來看下吧
效果圖:
圖(1)初始圖
圖(2)點擊展開圖
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style> *{ 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; } </style> <script> 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<h2Len;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(var i=0;i<aUlLen;i++){ aLi=aUl[i].getElementsByTagName('li'); for(var j=0;j<aLi.length;j++){ arrLi.push(aLi[j]); } } for(var i=0;i<arrLi.length;i++){ arrLi[i].onclick=function(){ for(var i=0;i<arrLi.length;i++){ arrLi[i].className=''; } this.className='hover'; } } } </script> </head> <body> <ul id="list"> <li class="lis"> <h2><div></div>大學同學</h2> <ul> <li>張三</li> <li>張三</li> <li>張三</li> <li>張三</li> </ul> </li> <li class="lis"> <h2><div></div>高中同學</h2> <ul> <li>李四</li> <li>李四</li> <li>李四</li> <li>李四</li> </ul> </li> <li class="lis"> <h2><div></div>初中同學</h2> <ul> <li>王五</li> <li>王五</li> <li>王五</li> <li>王五</li> </ul> </li> </ul> </body> </html>
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關文章
深入理解Javascript動態(tài)方法調用與參數(shù)修改的問題
這篇文章主要是對Javascript動態(tài)方法調用與參數(shù)修改的問題進行了詳細的分析介紹,需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12JS中的算法與數(shù)據(jù)結構之字典(Dictionary)實例詳解
這篇文章主要介紹了JS中的算法與數(shù)據(jù)結構之字典(Dictionary),結合實例形式詳細分析了javascript數(shù)據(jù)結構中字典的概念、原理、定義與常見使用方法,需要的朋友可以參考下2019-08-08BootStrap.css 在手機端滑動時右側出現(xiàn)空白的原因及解決辦法
這篇文章主要介紹了BootStrap.css 在手機端滑動時右側出現(xiàn)空白的原因及解決辦法的相關資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06