Heim  >  Artikel  >  Web-Frontend  >  jQuery verwendet serielles Schreiben, um den Faltmenüeffekt_jquery zu erreichen

jQuery verwendet serielles Schreiben, um den Faltmenüeffekt_jquery zu erreichen

WBOY
WBOYOriginal
2016-05-16 15:38:451089Durchsuche

本文实例讲述了jQuery采用连缀写法实现的折叠菜单效果。分享给大家供大家参考。具体如下:

这是一款jQuery采用连缀写法实现的折叠菜单效果,作者是位高手啊,自己用jQuery的连缀写法编写的,差不多是手风琴菜单,功能是实现了,不过有点担心效率,作者希望与高人一起交流进步。

运行效果截图如下:

在线演示地址如下:

http://demo.jb51.net/js/2015/jquery-lz-fade-in-menu-style-codes/

具体代码如下:

<!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>1-5-1</title>
<style>
/** 清除内外边距 **/
body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, /* structural elements 结构元素 */
dl, dt, dd, ul, ol, li, /* list elements 列表元素 */
pre, /* text formatting elements 文本格式元素 */
form, fieldset, legend, button, input, textarea, /* form elements 表单元素 */
th, td /* table elements 表格元素 */ {
 margin: 0;
 padding: 0;
}
body,button, input, select, textarea {
 font: 12px/1.5 tahoma, arial, \5b8b\4f53, sans-serif;
}
h1, h2, h3, h4, h5, h6 { font-size: 100%; }
address, cite, dfn, em, var { font-style: normal; } /* 将斜体扶正 */
code, kbd, pre, samp { font-family: courier new, courier, monospace; } /* 统一等宽字体 */
small { font-size: 12px; } /* 小于 12px 的中文很难阅读,让 small 正常化 */
ul, ol { list-style: none; }
/** 重置文本格式元素 **/
a { text-decoration: none; }
a:hover { text-decoration: underline; }
sup { vertical-align: text-top; } /* 重置,减少对行高的影响 */
sub { vertical-align: text-bottom; }
/** 重置表单元素 **/
legend { color: #000; } /* for ie6 */
fieldset, img { border: 0; } /* img 搭车:让链接里的 img 无边框 */
button, input, select, textarea { font-size: 100%; } /* 使得表单元素在 ie 下能继承字体大小 */
/* 注:optgroup 无法扶正 */
/** 重置表格元素 **/
table { border-collapse: collapse; border-spacing: 0; }
</style>
<style type="text/css">
#menu{width:300px;overflow:hidden}
#menu dt{background:#ccc;color:#fff;cursor:pointer}
#menu dd{background:#f4f4f4;color:#fff;;display:none}
#menu dt.hover{background:green}
</style>
<script type="text/javascript" src="jquery1.3.2.js" ></script>
<script type="text/javascript">
$(function(){
 $("dl").mouseover(function(){
  $(this).children('dt').addClass('hover').end().children("dd").show();
  $(this).siblings().children('dt').removeClass("hover").end().end().siblings().children("dd").hide();
 });
});
</script>
</head>
<body>
<div id="menu">
 <dl>
  <dt>第1章-认识jQuery</dt>
  <dd><a href="#">1.1-JavaScript和JavaScript库</a></dd>
  <dd><a href="#">1.2-加入jQuery</a></dd>
  <dd><a href="#">1.3-编写简单jQuery代码</a></dd>
  <dd><a href="#">1.4-jQuery对象和DOM对象</a></dd>
 </dl>
 <dl>
  <dt>第2章-jQuery选择器</dt>
  <dd><a href="#">2.1-jQuery选择器是什么</a></dd>
  <dd><a href="#">2.2-jQuery选择器的优势</a></dd>
  <dd><a href="#">2.3-jQuery选择器</a></dd>
  <dd><a href="#">2.4-应用jQuery改写示例</a></dd>
 </dl>
 <dl>
  <dt>第3章-jQuery中的DOM操作</dt>
  <dd><a href="#">3.1-DOM操作的分类</a></dd>
  <dd><a href="#">3.2-jQuery中的DOM操作</a></dd>
 </dl>
</div>
</body>
</html>

希望本文所述对大家的jQuery程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn