這篇文章主要介紹了怎么使用js實現(xiàn)帶三角符的手風(fēng)琴效果,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
創(chuàng)新互聯(lián)公司網(wǎng)站建設(shè)公司是一家服務(wù)多年做網(wǎng)站建設(shè)策劃設(shè)計制作的公司,為廣大用戶提供了網(wǎng)站制作、做網(wǎng)站,成都網(wǎng)站設(shè)計,1元廣告,成都做網(wǎng)站選創(chuàng)新互聯(lián)公司,貼合企業(yè)需求,高性價比,滿足客戶不同層次的需求一站式服務(wù)歡迎致電。
效果圖:
圖(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 h3{ height: 30px; line-height: 30px; overflow: hidden; background: lightsalmon; color: #f1f1f1; } #list h3.active{ background: pink; height: 30px; line-height: 30px; overflow: hidden; color: #666; } #list h3.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 h3 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('h3'); var aUl=oUl.getElementsByTagName('ul'); var h3Len=aH2.length; var aLi=null; var arrLi=[]; var aUlLen=aUl.length; for(var i=0;i<h3Len;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"> <h3><div></div>大學(xué)同學(xué)</h3> <ul> <li>張三</li> <li>張三</li> <li>張三</li> <li>張三</li> </ul> </li> <li class="lis"> <h3><div></div>高中同學(xué)</h3> <ul> <li>李四</li> <li>李四</li> <li>李四</li> <li>李四</li> </ul> </li> <li class="lis"> <h3><div></div>初中同學(xué)</h3> <ul> <li>王五</li> <li>王五</li> <li>王五</li> <li>王五</li> </ul> </li> </ul> </body> </html>
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“怎么使用js實現(xiàn)帶三角符的手風(fēng)琴效果”這篇文章對大家有幫助,同時也希望大家多多支持創(chuàng)新互聯(lián),關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
分享名稱:怎么使用js實現(xiàn)帶三角符的手風(fēng)琴效果
文章分享:http://jinyejixie.com/article18/iicedp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站維護、自適應(yīng)網(wǎng)站、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站制作、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)