原生态js展开收缩
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Document</title>
<style type="text/css">
*{margin: 0; padding: 0;}
body{max-width: 640px; margin: 0 auto; background-color: #ddd;}
a{text-decoration: none; color: #333;}
.public_header{ height: 40px; line-height: 40px; border-bottom:1px solid #ebebeb; position: relative; background-color: #fff; }
.ph_icon_menu{ position: absolute; right: 0;top:0;width: 40px; height: 40px; display: block;}
.ph_icon_menu i{display: block;border-color:#f60;border-width:3px 0;border-style: solid;width: 20px;height:11px;margin:11px auto 0;position: relative;}
.ph_icon_menu i:before{content: "";position: absolute;left:0;top:4px;width: 20px;height:3px;background-color:#f60;}
.nav{ background-color: #fff; overflow: hidden; display: none; }
.nav a{ width: 25%; float: left; display: block; height: 30px; line-height: 30px; box-sizing: border-box; border-right: 1px solid #ebebeb; border-bottom: 1px solid #ebebeb; text-align: center; font-weight: 700; font-size: 14px;}
.red{ color: red; text-align: center; margin-top: 150px; }
</style>
</head>
<body>
<div class="public_header"><a href="javascript:;" class="ph_icon_menu" onclick="menuShowHide();"><i></i></a></div>
<div class="nav" id="J_menu_content">
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">7</a>
<a href="#">8</a>
</div>
<script type="text/javascript">
//第一种写法
// var obj = document.getElementById("J_menu_content");
// function menuShowHide() {
// if (obj.style.display == "block") {
// obj.style.display = "none";
// }else{
// obj.style.display ="block";
// }
// }
//第二种写法
var type = 1;
var obj = document.getElementById('J_menu_content');
function menuShowHide() {
if (type) {
obj.style.display="block";
type = 0;
}else {
obj.style.display="none";
type = 1;
}
}
</script> <p class="red">注意:a标签要加上javascript:;才可以点击出效果</p> </body>
</html>
效果如图:

展开后:

如果文章中有不对之处,随时欢迎您的纠正~~
原生态js展开收缩的更多相关文章
- js 展开&收缩 二种
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 原生态js展开高度自适应100%
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- js实现的侧边栏展开收缩效果
原文地址:http://www.softwhy.com/forum.php?mod=viewthread&tid=12246 <!DOCTYPE html> <html> ...
- jQuery弹性展开收缩菜单插件gooey.js
分享一款基于jQuery弹性展开收缩菜单插件gooey.js.这是一款基于gooey.js插件实现的弹性菜单特效代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <hea ...
- 右上角鼠标滑过展开收缩动画效果js代码的演示页面
http://files.cnblogs.com/files/tanlingdangan/top_right.rar.gz 右上角鼠标滑过展开收缩动画效果js代码的演示页面http://www.51x ...
- js之展开收缩菜单,用到window.onload ,onclick,
目标效果:点击标签1,如果列表标签的style的display是block,改成none,否则改成block,来达到展开收缩菜单效果 一.准备阶段 html文件 <!DOCTYPE html&g ...
- SlickGrid example 5:带子项的展开收缩
带子项的展开收缩. 代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...
- HTML5每日一练之details展开收缩标签的应用
details标签的出现,为我们带来了更好的用户体验,不必为这种收缩展开的效果再编写JS来实现.注:目前仅Chrome支持此标签. details有一个新增加的子标签——summary,当鼠标点击su ...
- WordPress文章页添加展开/收缩功能
很多时候我们在WordPress上发布一些文章的时候里面都包含了很多的代码,我一般又不喜欢把代码压缩起来而喜欢让代码格式化显示,但是格式化显示通常会让文章内容看起来很多,不便于访问者浏览,所以今天就介 ...
随机推荐
- bootstrap-select.js 下拉框多选后动态赋值
话不多说先上demo 其实demo是从官网下载的 只稍作改动 由于没有搞清楚怎么上传源代码 就把官网的链接贴出来吧 https://github.com/silviomoreto/bootstrap- ...
- IE WebDeveloper--IE浏览器web调试工具
目前市面上比较火爆的浏览器内核提供商,有微软的IE.mozilla的firefox.谷歌的chrome.苹果的safari.IE浏览器下的项目过去占比非常大,近年随着其他浏览器厂商发展势头迅猛,过去的 ...
- CloudStack 注册模板脚本分析
注册系统虚拟机模板 /usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt 内容如下: usage ...
- 27-水池数目(dfs)
水池数目 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 南阳理工学院校园里有一些小河和一些湖泊,现在,我们把它们通一看成水池,假设有一张我们学校的某处的地图,这个地 ...
- spring aop博客记录
1.spring aop和事务失效 解决办法: http://blog.csdn.net/z2007130205/article/details/41284381 http://blog.csdn.n ...
- JMeter下载及安装配置完整版
特别需要注意的时,jdk版本和jmeter版本匹配问题. Jdk1.8对应apache-jmeter-3.3 Jmeter下载及安装配置 本文是在win7环境下安装使用jmeter,jmeter可以运 ...
- nuget get-package id显示不全
Get-Package | ft -AutoSize 参考 https://stackoverflow.com/questions/5036719/is-there-a-way-to-get-the- ...
- QML的默认属性default property
qml中,普通的属性,需要添加属性名称,属性内容,如 color: “red” 默认属性则可以直接书写,去掉方括号,在写重用的QML组件式比较有用,例如将一个QmL外部资源封装好,内部具体的item, ...
- Exception (1) Understanding Exception Handling
When an exception is thrown, it cannot be ignored--there must be some kind of notification or termin ...
- SSH2免密码登录OpenSSH
OpenSSH免密码登录SSH2http://blog.csdn.net/aquester/article/details/23836245 两个SSH2间免密码登录http://blog.csdn. ...