这里使用原生的javascript,用面向对象的方式创建一个容易维护使用方便的滑动菜单

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>javascript slide控件演示</title>
<style type="text/css">
/*reset*/
dl,ul,li,dt,dd{ margin:0; padding:0; list-style:none; }
/*silding*/
.silding{ width:200px; border:1px solid #ccc; line-height:25px; overflow:hidden;}
.silding dt{border-bottom:1px solid #ccc; background-color:#bebebe; cursor:pointer}
.silding dd{ display:none; background:#efefef; overflow:hidden; font-size:12px; }
.silding .active{ font-weight:bold;}
</style>
<script type="text/javascript">
function Slider(i, panelHeight) { //dto
this.index = i;
this.panelHeight = panelHeight;
}

//class Sliding {
function Sliding(activeIndex) {
this.commands = [];
this.panels = [];
this.activeIndex = activeIndex || 0;
this.sliderCache = {};
}
Sliding.prototype = {
//绑定事件
init: function(eventName, activeCssClass) {
var _this = this;
var cmds = _this.commands;
_this.activeClass = activeCssClass;
for (var i = 0, n = cmds.length; i < n; i++) {
cmds[i]["on" + eventName] = function(e) {
_this.handel(this, e);
}
cmds[i].index = i;
if (i == _this.activeIndex) {
_this.sliderCache = new Slider(i, _this.panels[i].offsetHeight);
}
}

},
//事件处理函数
handel: function(elem, args) {
var _this = this;
var index = elem.index;
var cacheIndex = _this.sliderCache.index;
var cacheElem = _this.commands[cacheIndex];
if (index == cacheIndex) return;
var showPanel = _this.panels[index];
var hidePanel = _this.panels[cacheIndex];
var h = parseInt(_this.sliderCache.panelHeight);
showPanel.style.height = "0px";
showPanel.style.display = "block";
_this.tween(hidePanel, showPanel, h);
elem.className = _this.activeClass;
cacheElem.className = cacheElem.className.replace(eval("/ ?"+_this.activeClass+" ?/"),"");
_this.sliderCache = new Slider(index, h);

},
//动画算法
tween: function(obj0, obj1, h) {
_this = arguments.callee;
var step = 20;
if ("\v" == "v") {
step = 30;
}
if (h > 0) {
var h0 = obj0.offsetHeight;
var h1 = obj1.offsetHeight;
if (h < step) {
obj0.style.display = "none";
obj0.style.height = (h1 + h) + "px";
obj1.style.height = (h1 + h) + "px";

} else {
h = h - step;
obj0.style.height = (h0 - step) + "px";
obj1.style.height = (h1 + step) + "px";
setTimeout(function() {
_this(obj0, obj1, h)
},
50)
}
}
}
}
//}
</script>
</head>

<body>
<div id="silding" class="silding">
<dl>
<dt class="active">第一个一级菜单</dt>
<dd style="display:block;">
<ul>
<li><a href="#">第一个二级菜单</a></li>
<li>第一个二级菜单</li>
<li>第一个二级菜单</li>
</ul>
</dd>
</dl>
<dl>
<dt>第二个一级菜单</dt>
<dd>
<ul>
<li>第二个二级菜单</li>
<li>第二个二级菜单</li>
<li>第二个二级菜单</li>
</ul>
</dd>
</dl>
<dl>
<dt>第三个一级菜单</dt>
<dd>
<ul>
<li>第三个二级菜单</li>
<li>第三个二级菜单</li>
<li>第三个二级菜单</li>
</ul>
</dd>
</dl>
</div>
<script type="text/javascript">
var $sliding = document.getElementById("silding");
var s1 = new Sliding();
s1.commands = $sliding.getElementsByTagName("dt");
s1.panels = $sliding.getElementsByTagName("dd"); ;
s1.init("mouseover", "active");
</script>
</body>
</html>

使用javascript oop开发滑动(slide) 菜单控件的更多相关文章

  1. 实用的树形菜单控件tree

     jQuery plugin: Treeview  这个插件能够把无序列表转换成可展开与收缩的Tree. jQuery plugin: Treeview  jQuery  jstree  jsTree ...

  2. html树形菜单控件

    html树形菜单控件  链接 http://www.ithao123.cn/content-713974.html         jQuery plugin: Treeview  这个插件能够把无序 ...

  3. 【转】html树形菜单控件

    Query plugin: Treeview  这个插件能够把无序列表转换成可展开与收缩的Tree. 主页:http://bassistance.de/jQuery-plugins/jquery-pl ...

  4. Windows Store App JavaScript 开发:WinJS库控件

    在介绍了如何使用标准的HTML控件以及WinJS库中提供的新控件之后,下面来着重介绍WinJS库中几种常用的控件. (1)ListView控件 在开发Windows应用商店应用时可以使用ListVie ...

  5. Asp.net 菜单控件

    本文介绍的菜单控件采用的css 和ul list来显示菜单,生成的html小,无需javascript支持,对大部分的浏览器都支持,除ie6要单独修改css也可以使其支持. 通过本文可以了解asp.n ...

  6. Android开发中目前流行控件和知识点总结

    Android开发中目前流行控件和知识点总结   1.SlidingMenu 滑动菜单 应用案例:Facebook . Path 2.0 .人人.网易新闻 下载地址: https://github.c ...

  7. 自写JQ控件-树状菜单控件[demo下载]

    一个多月没有写博客了,最近也弄一个基于JQ的树状菜单控件,在此分享给大家.另外呢,通过这个例子分享一下怎么写JQ控件的. 事实上工作中,也是经常遇到的,有些时候自己想实现一些前端效果,用网上一些插件吧 ...

  8. SNF快速开发平台MVC-富文本控件集成了百度开源项目editor

    一.效果如下: 二.在框架当中调用代码如下: 1.在js里配置如下: <script type="text/javascript"> var viewModel =fu ...

  9. 简洁的Asp.net菜单控件

    http://www.cnblogs.com/ruinet/archive/2009/11/10/1599984.html asp.net自带的菜单控件采用的table和javascript,导致生成 ...

随机推荐

  1. Python的ASCII, GB2312, Unicode , UTF-8 相互转换

    ASCII 是一种字符集,包括大小写的英文字母.数字.控制字符等,它用一个字节表示,范围是 0-127 Unicode分为UTF-8和UTF-16.UTF-8变长度的,最多 6 个字节,小于 127 ...

  2. 【转】android 电容屏(二):驱动调试之基本概念篇

    关键词:android  电容屏 tp 工作队列 中断 多点触摸协议平台信息:内核:linux2.6/linux3.0系统:android/android4.0 平台:S5PV310(samsung ...

  3. http://home.cnblogs.com/

    说起编辑器,可能大部分人要推荐的是Vim和Emacs,本人用过Vim,功能确实强大,但是不是很习惯,之前一直有朋友推荐SUblime Text 2这款编辑器,然后这段时间就试了一下,就深深地喜欢上这款 ...

  4. cmd用到的基本操作

    dir #显示当前目录中的文件和子目录 dir /a #显示当前目录中的文件和子目录,包括隐藏文件和系统文件 a = all dir c: /a:d #显示 C 盘当前目录中的目录 d = direc ...

  5. magento后台登陆后,没任何提示,又跳转到登陆页面

    这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null

  6. |,&,<<,>>运算符

    << 位移运算符(>>相反了) /* * 题目: 2 << 3 = 10000 = 16 * 解答: 2向左移动三位,就变成了10000 * 十进制 二进制 * 2 ...

  7. 用Unity做的一个小游戏,仿照一个样例写的,个人认为文章写的不错,哈哈

  8. hadoop python and Twitter

    http://www.wubiaoblog.com/archives/1159 http://blog.csdn.net/anbo724 http://f.dataguru.cn/forum.php? ...

  9. oracle 通过透明网关gateway 连接sqlserver

    真实配置如下: 1.安装gateway 在一台单独的机器上,ip:172.30.40.29 2.配置listener.ora如下: 路径:  D:\product\11.2.0\tg_1\NETWOR ...

  10. iOS获取文件路径

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px "PingFang SC"; color: #008400 } p.p2 ...