<!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展开收缩的更多相关文章

  1. js 展开&收缩 二种

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 原生态js展开高度自适应100%

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. js实现的侧边栏展开收缩效果

    原文地址:http://www.softwhy.com/forum.php?mod=viewthread&tid=12246 <!DOCTYPE html> <html> ...

  4. jQuery弹性展开收缩菜单插件gooey.js

    分享一款基于jQuery弹性展开收缩菜单插件gooey.js.这是一款基于gooey.js插件实现的弹性菜单特效代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <hea ...

  5. 右上角鼠标滑过展开收缩动画效果js代码的演示页面

    http://files.cnblogs.com/files/tanlingdangan/top_right.rar.gz 右上角鼠标滑过展开收缩动画效果js代码的演示页面http://www.51x ...

  6. js之展开收缩菜单,用到window.onload ,onclick,

    目标效果:点击标签1,如果列表标签的style的display是block,改成none,否则改成block,来达到展开收缩菜单效果 一.准备阶段 html文件 <!DOCTYPE html&g ...

  7. SlickGrid example 5:带子项的展开收缩

    带子项的展开收缩.   代码: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Ty ...

  8. HTML5每日一练之details展开收缩标签的应用

    details标签的出现,为我们带来了更好的用户体验,不必为这种收缩展开的效果再编写JS来实现.注:目前仅Chrome支持此标签. details有一个新增加的子标签——summary,当鼠标点击su ...

  9. WordPress文章页添加展开/收缩功能

    很多时候我们在WordPress上发布一些文章的时候里面都包含了很多的代码,我一般又不喜欢把代码压缩起来而喜欢让代码格式化显示,但是格式化显示通常会让文章内容看起来很多,不便于访问者浏览,所以今天就介 ...

随机推荐

  1. windows系统mysql-5.7.19官方绿色版zip包安装教程

    环境: 系统环境 Windows 10 64位 mysql版本 5.7.19 一.万变不离的下载 下载页面:https://dev.mysql.com/downloads/mysql/ 点击 Down ...

  2. unity自带寻路Navmesh入门教程

    http://liweizhaolili.blog.163.com/blog/static/16230744201271161310135/ http://liweizhaolili.blog.163 ...

  3. Jenkins中Jelly邮件模板的配置

    [链接]Jenkins中Jelly邮件模板的配置http://blog.csdn.net/hwhua1986/article/details/47975237

  4. OSG QT

    https://blog.csdn.net/a_Treasure/article/details/82152245 https://www.bbsmax.com/A/kPzOQ4oo5x/ https ...

  5. Opencv 分水岭分割图片

    #include <iostream>#include <opencv2/opencv.hpp> using namespace std;using namespace cv; ...

  6. Sqlserver时间函数用法(二)

    --1. 当前系统日期.时间 select getdate() --2015-01-06 09:27:27.277 --2.时间操作 dateadd 在向指定日期加上一段时间的基础上,返回新的 dat ...

  7. Linux cloc

    一.简介 cloc是一个基于perl的.十分好用的代码统计工具,它所支持的语言还算十分丰富.不过,还是有很多用的较少的语言是不支持的.   二.安装配置 1)官网安装教程 http://cloc.so ...

  8. if-return 语句

    if(A > B): return A+1 return A-1 or if(A > B): return A+1 else: return A-1 +++++++++++++++++++ ...

  9. laravel @if

  10. Perl 学习笔记-目标操作

    1.在目录树中移动. 程序运行时会以当前工作目录作为相对路径的起点, 可以使用  chdir 操作符改变当前目录: chdir "/etc" or die "Can't ...