js實(shí)現(xiàn)可折疊展開的手風(fēng)琴菜單效果
本文實(shí)例講述了js實(shí)現(xiàn)可折疊展開的手風(fēng)琴菜單效果。分享給大家供大家參考。具體如下:
這是一款可折疊展開的菜單,手風(fēng)琴菜單,運(yùn)用CSS與JavaScript技術(shù)實(shí)現(xiàn)的合攏與伸展的網(wǎng)頁菜單,代碼簡潔,來自老外的代碼作品,希望大家喜歡。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-hidden-show-sfq-style-menu-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>折疊展開的菜單</title>
</head>
<body><style type="text/css">
.menutitle{
cursor:pointer;
margin-bottom: 5px;
background-color:#ECECFF;
color:#000000;
width:140px;
padding:2px;
text-align:center;
font-weight:bold;
/*/*/border:1px solid #000000;/* */
}
.submenu{
margin-bottom: 0.5em;
}
</style>
<script type="text/javascript">
if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}
function SwitchMenu(obj){
if(document.getElementById){
var el = document.getElementById(obj);
var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
if(el.style.display != "block"){ //DynamicDrive.com change
for (var i=0; i<ar.length; i++){
if (ar[i].className=="submenu") //DynamicDrive.com change
ar[i].style.display = "none";
}
el.style.display = "block";
}else{
el.style.display = "none";
}
}
}
</script>
<!-- Keep all menus within masterdiv-->
<div id="masterdiv">
<div class="menutitle" onclick="SwitchMenu('sub1')">Site Menu</div>
<span class="submenu" id="sub1">
- <a href="#">What's New</a><br>
- <a href="#">What's hot</a><br>
- <a href="#">Revised Scripts</a><br>
- <a href="#">More Zone</a>
</span>
<div class="menutitle" onclick="SwitchMenu('sub2')">FAQ/Help</div>
<span class="submenu" id="sub2">
- <a href="#">Usage Terms</a><br>
- <a href="#">DHTML FAQs</a><br>
- <a href="#">Scripts FAQs</a>
</span>
<div class="menutitle" onclick="SwitchMenu('sub3')">Help Forum</div>
<span class="submenu" id="sub3">
- <a href="#">Coding Forums</a><br>
</span>
<div class="menutitle" onclick="SwitchMenu('sub4')">Cool Links</div>
<span class="submenu" id="sub4">
- <a >JavaScript Kit</a><br>
- <a href="http://www.dhdzp.com">腳本之家</a><br>
- <a >Cool Text</a><br>
</span>
</div>
</body>
</html>
希望本文所述對大家的JavaScript程序設(shè)計(jì)有所幫助。
- 純js實(shí)現(xiàn)手風(fēng)琴效果代碼
- 使用ReactJS實(shí)現(xiàn)tab頁切換、菜單欄切換、手風(fēng)琴切換和進(jìn)度條效果
- js實(shí)現(xiàn)簡單的手風(fēng)琴效果
- 原生js做的手風(fēng)琴效果的導(dǎo)航菜單
- Vue.js手風(fēng)琴菜單組件開發(fā)實(shí)例
- 純js實(shí)現(xiàn)手風(fēng)琴效果
- JS實(shí)現(xiàn)圖片手風(fēng)琴效果
- 原生JS實(shí)現(xiàn)垂直手風(fēng)琴效果
- Html5 js實(shí)現(xiàn)手風(fēng)琴效果
- js實(shí)現(xiàn)簡單手風(fēng)琴效果
相關(guān)文章
uni-app 組件里面獲取元素寬高的實(shí)現(xiàn)
這篇文章主要介紹了uni-app 組件里面獲取元素寬高的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Javascript學(xué)習(xí)筆記-詳解in運(yùn)算符
in運(yùn)算符是javascript語言中比較特殊的一個(gè),可以單獨(dú)使用作為判斷運(yùn)算符,也常被用于for...in循環(huán)中遍歷對象屬性2011-09-09
使用JavaScript實(shí)現(xiàn)一個(gè)錄屏插件
不知道大家平時(shí)都是使用什么錄屏軟件呢,有沒有想過只用JavaScript我們也可以快速實(shí)現(xiàn)一個(gè)錄屏插件呢,感興趣的小伙伴就跟隨小編一起學(xué)習(xí)一下吧2024-10-10

