原生态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上发布一些文章的时候里面都包含了很多的代码,我一般又不喜欢把代码压缩起来而喜欢让代码格式化显示,但是格式化显示通常会让文章内容看起来很多,不便于访问者浏览,所以今天就介 ...
随机推荐
- Build/Run Instructions for Codec Engine Examples
General Information This page explains how to build the examples provided in the Codec Engine (CE) p ...
- centos7 安装wxPython
*** exact error that occured. This usually means GTK+ is incorrectly installed. configure: error: ...
- pyinstaller打包后运行提示找不到模块
截止到2017年9月20号,pyinstaller只支持到python3.5,如果需要支持到3.6,需要自己在github上下载pyinstaller的开发版. 在打包时候,并没有提示错误,可以顺利打 ...
- 压力测试工具--Siege
Siege是一款开源的压力测试工具,设计用于评估WEB应用在压力下的承受能力.可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行.s ...
- VUE+WebPack游戏设计:'乘法防线'游戏设计
- 【CodeForces - 235C】Cyclical Quest 【后缀自动机】
题意 给出一个字符串s1和q个询问,每个询问给出一个字符串s2,问这个询问的字符串的所有不同的周期串在s1中出现的次数的和. 分析 对于s1建后缀自动机.对于询问的每个字符串s2,我们按照处理循环串的 ...
- SpringBoot01 InteliJ IDEA安装、Maven配置、创建SpringBoot项目、yml属性配置、多环境配置、自定义properties配置
1 IntelliJ IDEA 安装 下载地址:点击前往 注意:需要下载专业版本的,注册码在网上随便搜一个就行啦 2 MAVEN工具的安装 2.1 获取安装包 下载地址:点击前往 2.2 安装过程 到 ...
- Sql Server 2008R2 数据库发布与订阅
背景描述: 发布服务器A: (远程端) , 数据库服务名: GUANWANG1 订阅服务器B: (本机) , 数据库服务名: PC-LLRDBA 需要从服务器A中数据库发布,然后在B中订阅A发布 ...
- 更改IDEA高亮字体背景颜色
IDEA工具中依次进入file -> settings -> editor -> colors Scheme -> general,在右侧窗口中将result.i 都改成自己 ...
- 对比Nginx配置文件差异
一.概要: Python2 官方文档:https://docs.python.org/2/library/difflib.html Python2 官方文档:https://docs.python.o ...