web前端|js教程
javascript,显示和隐藏div
web前端-js教程
javascript实现显示和隐藏div方法汇总
空调维修网站源码,vscode新窗口打开项目,ubuntu屏幕不全,tomcat用什么监控,图片爬虫论坛,php 读取文件方法,南沙区seo优化哪里好,5173网站源码,app产品定义模板lzw
15种方法实现显示和隐藏div
var oBox = $(ox);var oList = $(oBox,ul)[0];var data = [display,visibility,absolute,margin负值, elative,width/height,opacity/rgba,hidden,skew,scale, ranslate, otate,overflow,z-index,order-box]; //生成结构function fnNew(i){ var sHtml = \; sHtml +=
\\\
\
第+ (i+1) +种方法:
+ data[i]+
; var element = document.createElement(li); element.className = in; element.innerHTML = sHtml; oList.appendChild(element); } for(var i = 0; i < data.length; i++){ fnNew(i); var oIn = oList.getElementsByTagName(li)[i]; var aBtn = oIn.getElementsByTagName(utton); var oShow = oIn.getElementsByTagName(div)[1]; for(var j = 0 ; j < 2; j++){ aBtn[j].m = oShow; aBtn[j].i = i; aBtn[j].j = j; aBtn[j].onclick = function(){ fn(this.m,this.j,this.i); } } }function fn(obj,switcher,index){ switch(index){ //【方法一】display: block/none case 0: if(!switcher){ obj.style.display = lock; }else{ obj.style.display = one; } break; //【方法二】visibility:true/false case 1: if(!switcher){ obj.style.visibility = visible; }else{ obj.style.visibility = hidden; } break; //【方法三】absolute+top/static case 2: if(!switcher){ obj.style.cssText = position:static; }else{ obj.style.cssText = position:absolute;top:-999px; } break; //【方法四】margin-top case 3: if(!switcher){ obj.style.cssText = margin-top: 10px; }else{ obj.style.cssText = margin-top:-999px; } break; //【方法五】relative + top / static case 4: if(!switcher){ obj.style.cssText = position: static; }else{ obj.style.cssText = position: relative; top: -999px; } break; //【方法六】width/height case 5: if(!switcher){ obj.style.cssText = width:100px; padding: 10px; }else{ obj.style.cssText = width:0; padding: 0; } break; //【方法七】opacity/rgba case 6: if(!switcher){ obj.style.opacity = 1; }else{ obj.style.opacity = ; } break; //【方法八】hidden case 7: if(!switcher){ obj.hidden = false; }else{ obj.hidden = true; } break; //【方法九】skew case 8: if(!switcher){ obj.style.transform = skew(0); }else{ obj.style.transform = skew(90deg); } break; //【方法十】scale case 9: if(!switcher){ obj.style.transform = scale(1); }else{ obj.style.transform = scale(0); } break; //【方法十一】translate case 10: if(!switcher){ obj.style.transform = ranslateX(0); }else{ obj.style.transform = ranslateX(-999px); } break; //【方法十二】rotate case 11: if(!switcher){ obj.style.transform = otateX(0); }else{ obj.style.transform = otateX(90deg); } break; //【方法十三】overflow case 12: if(!switcher){ obj.style.cssText = ransform: translateX(0); }else{ obj.style.cssText = ransform: translateX(220px); } break; //【方法十四】z-index case 13: var element = document.createElement(div); element.style.cssText = height: 100px;width: 120px;padding: 10px;background-color: white; margin-top: 10px;margin-left: 13%;position:absolute ;z-index: -1; obj.parentNode.appendChild(element); if(!switcher){ obj.style.cssText = \; obj.parentNode.style.position = static; }else{ obj.style.cssText = z-index:-1; position:absolute;margin-left: 13%;; obj.parentNode.style.position = elative; } break; //【方法十五】border-box case 14: if(!switcher){ obj.style.cssText = \; }else{ obj.style.cssText = padding: 0; box-sizing: border-box; border: 50px solid white;; } break; }}
我们再来看下其他小伙伴是如何实现的
material design动画源码,vscode怎么修改图片大小,ubuntu卡在硬盘,tomcat 只能打开官网,影视爬虫TV,如何访问php页面,四川seo有哪些工作lzw
居中的DIV
示例三:
手机网页源码插件下载,ubuntu软件源路径,水爬虫的图片,php 提醒,seo 运维lzw
先来看一个最简单的实例,这个可以实现显示和隐藏层
function $_(id){ return document.getElementById(id);};function display(x){ $(x).style.display=($(x).style.display=="none")?"":"none";};
下面是关闭层,其实原理 是一样的只是加了个效果。
function dianji(){ x=document.getElementById("xian"); x.style.display="block"; return false; } function guanbi(name){ var c=document.getElementById("wangyan").value; if(c==3){x.style.display= one; return false; } }