做好的手风琴效果如下,具体看代码:
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="/UploadFiles/2021-04-02/common.js"><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";
}
}
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。