原生js做的手风琴效果的导航菜单_javascript技巧
程序员文章站
2022-05-17 18:13:46
...
做好的手风琴效果如下,具体看代码:
html代码
Accordion
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";
}
}
html代码
复制代码 代码如下:
level one
- first item
- second item
- third item
level one
- first item
- second item
- third item
level one
- first item
- second item
- third item
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";
}
}
下一篇: thinkphp框架中系统内存溢出
推荐阅读
-
原生Js与jquery的多组处理, 仅展开一个区块的折叠效果_javascript技巧
-
原生Js实现按的数据源均分时间点幻灯片效果(已封装)_javascript技巧
-
用原生js做个简单的滑动效果的回到顶部_javascript技巧
-
顶部缓冲下拉菜单导航特效的JS代码_javascript技巧
-
javascript实现带下拉子菜单的导航菜单效果_javascript技巧
-
用JS做的简单的可折叠的两级树形菜单_javascript技巧
-
原生Js与jquery的多组处理, 仅展开一个区块的折叠效果_javascript技巧
-
JS+CSS实现类似QQ好友及黑名单效果的树型菜单_javascript技巧
-
顶部缓冲下拉菜单导航特效的JS代码_javascript技巧
-
javascript实现带下拉子菜单的导航菜单效果_javascript技巧