jquery实现的Accordion折叠面板效果代码


Posted in Javascript onSeptember 02, 2015

本文实例讲述了jquery实现的Accordion折叠面板效果代码。分享给大家供大家参考。具体如下:

这是一款Accordion折叠面板,折叠菜单代码,简单Accordion效果,采用CSS与jQuery实现,鼠标点击后展开,再次点击后折叠起来。是网上很常用的手风琴效果。

运行效果截图如下:

jquery实现的Accordion折叠面板效果代码

在线演示地址如下:

具体代码如下:

<!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>Simple Accordion with CSS & jQuery</title>
<style type="text/css">
html {
 overflow-Y: scroll;
}
body {
 font: 10px normal Arial, Helvetica, sans-serif;
 margin: 0;
 padding: 0;
 line-height: 1.7em;
}
*, * focus {
 outline: none;
 margin: 0;
 padding: 0;
}
.container {
 width: 500px;
 margin: 0 auto;
}
h1 {
 font: 4em normal Georgia, 'Times New Roman', Times, serif;
 text-align:center;
 padding: 20px 0;
 color: #aaa;
}
h1 span { color: #666; }
h1 small{
 font: 0.3em normal Verdana, Arial, Helvetica, sans-serif;
 text-transform:uppercase;
 letter-spacing: 0.5em;
 display: block;
 color: #666;
}
h2.acc_trigger {
 padding: 0; margin: 0 0 5px 0;
 background: url(images/h2_trigger_a.gif) no-repeat;
 height: 46px; line-height: 46px;
 width: 500px;
 font-size: 2em;
 font-weight: normal;
 float: left;
}
h2.acc_trigger a {
 color: #fff;
 text-decoration: none;
 display: block;
 padding: 0 0 0 50px;
}
h2.acc_trigger a:hover {
 color: #ccc;
}
h2.active {background-position: left bottom;}
.acc_container {
 margin: 0 0 5px; padding: 0;
 overflow: hidden;
 font-size: 1.2em;
 width: 500px;
 clear: both;
 background: #f0f0f0;
 border: 1px solid #d6d6d6;
 -webkit-border-bottom-right-radius: 5px;
 -webkit-border-bottom-left-radius: 5px;
 -moz-border-radius-bottomright: 5px;
 -moz-border-radius-bottomleft: 5px;
 border-bottom-right-radius: 5px;
 border-bottom-left-radius: 5px; 
}
.acc_container .block {
 padding: 20px;
}
.acc_container .block p {
 padding: 5px 0;
 margin: 5px 0;
}
.acc_container h3 {
 font: 2.5em normal Georgia, "Times New Roman", Times, serif;
 margin: 0 0 10px;
 padding: 0 0 5px 0;
 border-bottom: 1px dashed #ccc;
}
.acc_container img {
 float: left;
 margin: 10px 15px 15px 0;
 padding: 5px;
 background: #ddd;
 border: 1px solid #ccc;
}
</style>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container
//On Click
$('.acc_trigger').click(function(){
 if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
  $('.acc_trigger').removeClass('active').next().slideUp(); //Remove all .acc_trigger classes and slide up the immediate next container
  $(this).toggleClass('active').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
 }
 return false; //Prevent the browser jump to the link anchor
});
});
</script>
</head>
<body>
<h1>Simple Accordion with <span>CSS & jQuery</span><small>by Soh Tanaka | <a href="#">View Tutorial</a></small></h1>
<div class="container">
 <h2 class="acc_trigger"><a href="#">Web Design & Development</a></h2>
 <div class="acc_container">
  <div class="block">
   <h3>Need a Website?</h3>
   <a href="#"><img src="img1.gif" alt="" /></a>
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
   <p>Praesent duis vel similis usitas camur, nostrud eros opes verto epulae feugiat ad. Suscipit modo magna letalis amet et tego accumsan facilisi, meus. Vindico luptatum blandit ulciscor mos caecus praesent sed meus velit si quis lobortis praemitto, uxor. </p>
  </div>
 </div>
 <h2 class="acc_trigger"><a href="#">Logo / Corporate Identity</a></h2>
 <div class="acc_container">
  <div class="block">
   <h3>Need a Logo?</h3>
   <a href="#"><img src="img2.gif" alt="" /></a>
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
   <p>Praesent duis vel similis usitas camur, nostrud eros opes verto epulae feugiat ad. Suscipit modo magna letalis amet et tego accumsan facilisi, meus. Vindico luptatum blandit ulciscor mos caecus praesent sed meus velit si quis lobortis praemitto, uxor. </p>
  </div>
 </div>
 <h2 class="acc_trigger"><a href="#">Seach Engine Optimization</a></h2>
 <div class="acc_container">
  <div class="block">
   <h3>Need to be Heard?</h3>
   <a href="#"><img src="img3.gif" alt="" /></a>
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
   <p>Praesent duis vel similis usitas camur, nostrud eros opes verto epulae feugiat ad. Suscipit modo magna letalis amet et tego accumsan facilisi, meus. Vindico luptatum blandit ulciscor mos caecus praesent sed meus velit si quis lobortis praemitto, uxor. </p>
  </div>
 </div>
 <h2 class="acc_trigger"><a href="#">eCommerce</a></h2>
 <div class="acc_container">
  <div class="block">
   <h3>Have Product to Sell?</h3>
   <a href="#"><img src="img4.gif" alt="" /></a>
   <p>Consequat te olim letalis premo ad hos olim odio olim indoles ut venio iusto. Euismod, sagaciter diam neque antehabeo blandit, jumentum transverbero luptatum. Lenis vel diam praemitto molior facilisi facilisi suscipere abico, ludus, at. Wisi suscipere nisl ad capto comis esse, autem genitus. Feugiat immitto ullamcorper hos luptatum gilvus eum. Delenit patria nunc os pneum acsi nulla magna singularis proprius autem exerci accumsan. </p>
   <p>Praesent duis vel similis usitas camur, nostrud eros opes verto epulae feugiat ad. Suscipit modo magna letalis amet et tego accumsan facilisi, meus. Vindico luptatum blandit ulciscor mos caecus praesent sed meus velit si quis lobortis praemitto, uxor. </p>
  </div>
 </div>
</div>
</body>
</html>

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

Javascript 相关文章推荐
IE6弹出“已终止操作”的解决办法
Nov 27 Javascript
js分解url参数(面向对象-极简主义法应用)
Aug 09 Javascript
Javascript 多浏览器兼容总结(实战经验)
Oct 30 Javascript
利用浏览器全屏api实现js全屏
Jan 16 Javascript
简单模拟node.js中require的加载机制
Oct 27 Javascript
详解Vue 实例中的生命周期钩子
Mar 21 Javascript
jQuery实现简单的回到顶部totop功能示例
Oct 16 jQuery
vue组件编写之todolist组件实例详解
Jan 22 Javascript
详解node.js的http模块实例演示
Jul 12 Javascript
分享Angular http interceptors 拦截器使用(推荐)
Nov 10 Javascript
JavaScript大数相加相乘的实现方法实例
Oct 18 Javascript
JavaScript实现滚动加载更多
Dec 27 Javascript
jQuery实现带延迟效果的滑动菜单代码
Sep 02 #Javascript
jquery实现顶部向右伸缩的导航区域代码
Sep 02 #Javascript
jquery实现的Banner广告收缩效果代码
Sep 02 #Javascript
js实现拉幕效果的广告代码
Sep 02 #Javascript
JS实现弹性漂浮效果的广告代码
Sep 02 #Javascript
jquery实现可关闭的倒计时广告特效代码
Sep 02 #Javascript
jquery实现滑屏大图定时收缩为小banner图片的广告代码
Sep 02 #Javascript
You might like
php文件夹与文件目录操作函数介绍
2013/09/09 PHP
主流PHP框架的优缺点对比分析
2014/12/25 PHP
php访问数组最后一个元素的函数end()用法
2015/03/18 PHP
[原创]PHP字符串中插入子字符串方法总结
2016/05/06 PHP
Smarty高级应用之缓存操作技巧分析
2016/05/14 PHP
PHP随机获取未被微信屏蔽的域名(微信域名检测)
2017/03/19 PHP
laravel 框架执行流程与原理简单分析
2020/02/01 PHP
javascript权威指南 学习笔记之变量作用域分享
2011/09/28 Javascript
jQuery自定义添加&quot;$&quot;与解决&quot;$&quot;冲突的方法
2015/01/19 Javascript
json实现添加、遍历与删除属性的方法
2016/06/17 Javascript
Node.js包管理器Yarn的入门介绍与安装
2016/10/17 Javascript
关于定制FileField中的上传文件名称问题
2017/08/22 Javascript
分析javascript中9 个常见错误阻碍你进步
2017/09/18 Javascript
vue中promise的使用及异步请求数据的方法
2018/11/08 Javascript
Vuex中的State使用介绍
2019/01/19 Javascript
layui实现数据表格自定义数据项
2019/10/26 Javascript
微信小程序学习总结(二)样式、属性、模板操作分析
2020/06/04 Javascript
[46:00]Ti4 冒泡赛第二轮LGD vs C9 2
2014/07/14 DOTA
[41:52]2018DOTA2亚洲邀请赛3月29日 小组赛A组 TNC VS OpTic
2018/03/30 DOTA
[00:12]2018DOTA2亚洲邀请赛 Somnus丶M出阵单挑
2018/04/06 DOTA
Python程序设计入门(5)类的使用简介
2014/06/16 Python
用实例分析Python中method的参数传递过程
2015/04/02 Python
讲解Python中运算符使用时的优先级
2015/05/14 Python
python3的print()函数的用法图文讲解
2019/07/16 Python
python2使用bs4爬取腾讯社招过程解析
2019/08/14 Python
TensorFlow绘制loss/accuracy曲线的实例
2020/01/21 Python
python3中确保枚举值代码分析
2020/12/02 Python
苹果香港官方商城:Apple香港
2016/09/14 全球购物
英国第一蛋白粉品牌:Myprotein
2016/09/14 全球购物
Audible英国:有声读物,30天免费试用
2019/10/16 全球购物
Java面试题:请问一下代码输出是什么
2015/05/27 面试题
文秘大学生求职信
2014/02/25 职场文书
紧急通知
2015/04/17 职场文书
2015年市场部工作总结
2015/04/30 职场文书
新闻通讯稿模板
2015/07/22 职场文书
开学典礼校长致辞
2015/07/29 职场文书