uikit框架中导航菜单手风琴效果怎么显示出来

求具体代码~要uikit的... 求具体代码~要uikit的 展开
 我来答
匿名用户
2014-04-24
展开全部


做好的手风琴效果如下,具体看代码:

html代码

代码如下:复制代码

<!doctype html>
<html> <head>
<meta charset="utf-8">

<title>Accordion</title>

<style>

#accordion{

width:200px;

}

#accordion ul{

list-style: none;

display:none;

}

.first-level{

background-color: #d8d8d8;

background-color: rgba(236, 208, 208, 0.53);

border-radius: 4px;

display: block;

cursor: pointer;

position: relative;

margin: 2px 0 0 0;

padding: 8px;

min-height: 0;
} </style> </head> <body>
<div id="accordion">

<div>

<h3 class="first-level">level one</h3>

<ul>

<li>first item</li>

<li>second item</li>

<li>third item</li>
</ul> </div> <div>
<h3 class="first-level">level one</h3>

<ul>

<li>first item</li>

<li>second item</li>

<li>third item</li>
</ul> </div> <div>
<h3 class="first-level">level one</h3>

<ul>

<li>first item</li>

<li>second item</li>

<li>third item</li>
</ul> </div> </div>
<script src="common.js"></script>

<script>

var heads = document.querySelectorAll(".first-level");

function headClick(event){

var target = EventUtil.getTarget(event);

toggleDisplay(target.parentNode.querySelector("ul"));

}

for(var i=0;i<heads.length;i++){

EventUtil.addHandler(heads[i], "click", headClick);

}

window.onunload = function (){

for(var i=0;i<heads.length;i++){

EventUtil.removeHandler(heads[i], "click", headClick);

}

heads = null;

}

common.js文件

代码如下:复制代码

var EventUtil = {

addHandler : function (element, type, handler) {

if (element.addEventListener) {

element.addEventListener(type, handler, false);

} else if (element.attachEvent) {

element.attachEvent("on" + type, handler);

} else {

element["on" + type] = handler;
} },
removeHandler : function (element, type, handler) {

if (element.removeEventListener) {

element.removeEventListener(type, handler, false);

} else if (element.detachEvent) {

element.detachEvent("on" + type, handler);

} else {

element["on" + type] = null;
} },
getEvent : function (event) {

return event || window.event;

},

getTarget : function (event) {

return event.target || event.srcElement;
} }
var getStyle = function (el, style) {

if (el.currentStyle) {

style = style.replace(/\-(\w)/g, function (all, letter) {

return letter.toUpperCase();

});

var value = el.currentStyle[style];

return value;

} else {

return document.defaultView.getComputedStyle(el, null).getPropertyValue(style);
} }
var toggleDisplay = function (element) {

var display = getStyle(element, "display");

if (display == "none") {

element.style.display = "block";

} else {

element.style.display = "none";
} }
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式