以下是 jQuery FAQs问答垂直手风琴切换特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery FAQs问答垂直手风琴切换</title>
<link rel="stylesheet" type="text/css" href="css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/zzsc.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<dl>
<dt>Why am I so awesome?</dt>
<dd>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci aliquam incidunt itaque mollitia eligendi, doloribus commodi a culpa ratione aspernatur!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae rerum molestiae laboriosam nobis odit.</p>
</dd>
<dt>What is the meaning of life?</dt>
<dd>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci aliquam incidunt itaque mollitia eligendi, doloribus commodi a culpa ratione aspernatur!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae rerum molestiae laboriosam nobis odit.</p>
</dd>
<dt>How did I get here?</dt>
<dd>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci aliquam incidunt itaque mollitia eligendi, doloribus commodi a culpa ratione aspernatur!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae rerum molestiae laboriosam nobis odit.</p>
</dd>
<dt>Why am I doing this?</dt>
<dd>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci aliquam incidunt itaque mollitia eligendi, doloribus commodi a culpa ratione aspernatur!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae rerum molestiae laboriosam nobis odit.</p>
</dd>
</dl>
</div>
<script src="js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script type="text/javascript">
(function(){
$('dd').filter(':nth-child(n+4)').addClass('hide');
$('dl').on('click', 'dt', function() {
$(this).next().slideToggle(200);
});
})();
</script>
</body>
</html>
CSS代码(reset.css):
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}
article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}
body{line-height:1}
ol,ul{list-style:none}
blockquote,q{quotes:none}
blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}
table{border-collapse:collapse;border-spacing:0}
CSS代码(style.css):
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,600);body{background-color:#27AE60;}
.container{width:600px;font:14px/21px "Open Sans",Arial,sans-serif;color:#666;background-color:white;padding:20px;margin:40px auto;border-radius:5px;}
p{margin-bottom:10px;}
.hide{display:none;}
dt{font-size:19px;color:#669933;margin-bottom:20px;margin-left:26px;cursor:pointer;}
/* Triangle list item */
dt:before{content:"";border-color:transparent #ccc;border-style:solid;border-width:5px 0 5px 8px;display:block;height:0;width:0;left:-16px;top:17px;position:relative;}
dd{padding:20px;background:#FDFCFA;border-radius:5px;border:1px solid #F2EEE6;margin:20px 0 30px;position:relative;}
/* Triangle in definition container */
dd:after,dd:before{bottom:100%;left:6%;border:solid transparent;content:"";height:0;width:0;position:absolute;pointer-events:none;}
dd:after{border-color:rgba(136,183,213,0);border-color:transparent;border-bottom-color:#FDFCFA;border-width:15px;margin-left:-15px;}
dd:before{border-color:rgba(194,225,245,0);border-color:transparent;border-bottom-color:#F2EEE6;border-width:17px;margin-left:-17px;}
CSS代码(zzsc.css):
body{background:#494A5F;color:#D5D6E2;font-weight:500;font-size:1.05em;font-family:"Microsoft YaHei","宋体","Segoe UI","Lucida Grande",Helvetica,Arial,sans-serif,FreeSans,Arimo;}
a{color:#2fa0ec;text-decoration:none;outline:none;}
a:hover,a:focus{color:#74777b;}
.center{text-align:center;}