以下是 jQuery&CSS3手风琴特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Image Accordion with CSS3</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Image Accordion with CSS3" />
<meta name="keywords" content="accordion, images, slideshow, css3, css-only, web development, component, tutorial" />
<meta name="author" content="Ring Wing for Codrops" />
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" type="text/css" href="css/demo.css" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700,300,300italic' rel='stylesheet' type='text/css'>-->
<script type="text/javascript" src="js/modernizr.custom.79639.js"></script>
<!--[if lte IE 8]><style>.main{display:none;} .support-note .note-ie{display:block;}</style>
<![endif]-->
</head>
<body>
<div class="container">
<header>
<h1>Image Accordion <span>with CSS3</span></h1>
<h2>A css-only image accordion with "click" events.</h2>
<div class="support-note"><!-- let's check browser support with modernizr -->
<!--span class="no-cssanimations">CSS animations are not supported in your browser</span-->
<!--span class="no-csstransforms">CSS transforms are not supported in your browser</span-->
<!--span class="no-csstransforms3d">CSS 3D transforms are not supported in your browser</span-->
<span class="no-csstransitions">CSS transitions are not supported in your browser</span>
<span class="note-ie">Sorry, only modern browsers.</span>
</div>
</header>
<section class="main">
<div class="ia-container">
<figure>
<img src="images/1.jpg" alt="image01" />
<input type="radio" name="radio-set" checked="checked"/>
<figcaption><span>True Colors</span></figcaption>
<figure>
<img src="images/2.jpg" alt="image02" />
<input type="radio" name="radio-set" />
<figcaption><span>Honest Light</span></figcaption>
<figure>
<img src="images/3.jpg" alt="image03" />
<input type="radio" name="radio-set" />
<figcaption><span>Silent Serenity</span></figcaption>
<figure>
<img src="images/4.jpg" alt="image04" />
<input type="radio" name="radio-set" />
<figcaption><span>Warm Welcome</span></figcaption>
<figure>
<img src="images/5.jpg" alt="image05" />
<input type="radio" name="radio-set" />
<figcaption><span>Sensible Magic</span></figcaption>
<figure>
<img src="images/6.jpg" alt="image06" />
<input type="radio" name="radio-set" />
<figcaption><span>Lovely Midnight</span></figcaption>
<figure>
<img src="images/7.jpg" alt="image07" />
<input type="radio" name="radio-set" />
<figcaption><span>Illuminated Darkness</span></figcaption>
<figure>
<img src="images/8.jpg" alt="image08" />
<input id="ia-selector-last" type="radio" name="radio-set" />
<figcaption><span>Happy Child</span></figcaption>
</figure>
</figure>
</figure>
</figure>
</figure>
</figure>
</figure>
</figure>
</div><!-- ia-container -->
</section>
</div>
</body>
</html>
JS代码(modernizr.custom.79639.js):
/* Modernizr 2.5.3 (Custom Build) | MIT & BSD * Build:http://www.modernizr.com/download/#-cssanimations-csstransforms-csstransforms3d-csstransitions-shiv-cssclasses-teststyles-testprop-testallprops-prefixes-domprefixes */
;
window.Modernizr=function(a,b,c){
function z(a){
j.cssText=a}
function A(a,b){
return z(m.join(a+";
")+(b||""))}
function B(a,b){
return typeof a===b}
function C(a,b){
return!!~(""+a).indexOf(b)}
function D(a,b){
for(var d in a)if(j[a[d]]!==c)return b=="pfx"?a[d]:!0;
return!1}
function E(a,b,d){
for(var e in a){
var f=b[a[e]];
if(f!==c)return d===!1?a[e]:B(f,"function")?f.bind(d||b):f}
return!1}
function F(a,b,c){
var d=a.charAt(0).toUpperCase()+a.substr(1),e=(a+" "+o.join(d+" ")+d).split(" ");
return B(b,"string")||B(b,"undefined")?D(e,b):(e=(a+" "+p.join(d+" ")+d).split(" "),E(e,b,c))}
var d="2.5.3",e={
}
,f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={
}
.toString,m=" -webkit- -moz- -o- -ms- ".split(" "),n="Webkit Moz O ms",o=n.split(" "),p=n.toLowerCase().split(" "),q={
}
,r={
}
,s={
}
,t=[],u=t.slice,v,w=function(a,c,d,e){
var f,i,j,k=b.createElement("div"),l=b.body,m=l?l:b.createElement("body");
if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:h+(d+1),k.appendChild(j);
return f=["­
","<style>",a,"</style>"].join(""),k.id=h,(l?k:m).innerHTML+=f,m.appendChild(k),l||(m.style.background="",g.appendChild(m)),i=c(k,a),l?k.parentNode.removeChild(k):m.parentNode.removeChild(m),!!i}
,x={
}
.hasOwnProperty,y;
!B(x,"undefined")&&!B(x.call,"undefined")?y=function(a,b){
return x.call(a,b)}
:y=function(a,b){
return b in a&&B(a.constructor.prototype[b],"undefined")}
,Function.prototype.bind||(Function.prototype.bind=function(b){
var c=this;
if(typeof c!="function")throw new TypeError;
var d=u.call(arguments,1),e=function(){
if(this instanceof e){
var a=function(){
}
;
a.prototype=c.prototype;
var f=new a,g=c.apply(f,d.concat(u.call(arguments)));
return Object(g)===g?g:f}
return c.apply(b,d.concat(u.call(arguments)))}
;
return e}
);
var G=function(a,c){
var d=a.join(""),f=c.length;
w(d,function(a,c){
var d=b.styleSheets[b.styleSheets.length-1],g=d?d.cssRules&&d.cssRules[0]?d.cssRules[0].cssText:d.cssText||"":"",h=a.childNodes,i={
}
;
while(f--)i[h[f].id]=h[f];
e.csstransforms3d=(i.csstransforms3d&&i.csstransforms3d.offsetLeft)===9&&i.csstransforms3d.offsetHeight===3}
,f,c)}
([,["@media (",m.join("transform-3d),("),h,")","{
#csstransforms3d{
left:9px;
position:absolute;
height:3px;
}
}
"].join("")],[,"csstransforms3d"]);
q.cssanimations=function(){
return F("animationName")}
,q.csstransforms=function(){
return!!F("transform")}
,q.csstransforms3d=function(){
var a=!!F("perspective");
return a&&"webkitPerspective"in g.style&&(a=e.csstransforms3d),a}
,q.csstransitions=function(){
return F("transition")}
;
for(var H in q)y(q,H)&&(v=H.toLowerCase(),e[v]=q[H](),t.push((e[v]?"":"no-")+v));
return z(""),i=k=null,function(a,b){
function g(a,b){
var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;
return c.innerHTML="x<style>"+b+"</style>",d.insertBefore(c.lastChild,d.firstChild)}
function h(){
var a=k.elements;
return typeof a=="string"?a.split(" "):a}
function i(a){
var b={
}
,c=a.createElement,e=a.createDocumentFragment,f=e();
a.createElement=function(a){
var e=(b[a]||(b[a]=c(a))).cloneNode();
return k.shivMethods&&e.canHaveChildren&&!d.test(a)?f.appendChild(e):e}
,a.createDocumentFragment=Function("h,f","return function(){
var n=f.cloneNode(),c=n.createElement;
h.shivMethods&&("+h().join().replace(/\w+/g,function(a){
return b[a]=c(a),f.createElement(a),'c("'+a+'")'}
)+");
return n}
")(k,f)}
function j(a){
var b;
return a.documentShived?a:(k.shivCSS&&!e&&(b=!!g(a,"article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{
display:block}
audio{
display:none}
canvas,video{
display:inline-block;
*display:inline;
*zoom:1}
[hidden]{
display:none}
audio[controls]{
display:inline-block;
*display:inline;
*zoom:1}
mark{
background:#FF0;
color:#000}
")),f||(b=!i(a)),b&&(a.documentShived=b),a)}
var c=a.html5||{
}
,d=/^<|^(?:button|form|map|select|textarea)$/i,e,f;
(function(){
var a=b.createElement("a");
a.innerHTML="<xyz></xyz>",e="hidden"in a,f=a.childNodes.length==1||function(){
try{
b.createElement("a")}
catch(a){
return!0}
var c=b.createDocumentFragment();
return typeof c.cloneNode=="undefined"||typeof c.createDocumentFragment=="undefined"||typeof c.createElement=="undefined"}
()}
)();
var k={
elements:c.elements||"abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video",shivCSS:c.shivCSS!==!1,shivMethods:c.shivMethods!==!1,type:"default",shivDocument:j}
;
a.html5=k,j(b)}
(this,b),e._version=d,e._prefixes=m,e._domPrefixes=p,e._cssomPrefixes=o,e.testProp=function(a){
return D([a])}
,e.testAllProps=F,e.testStyles=w,g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+t.join(" "):""),e}
(this,this.document);
CSS代码(demo.css):
@import url('normalize.css');/* General Demo Style */
body{font-family:'Open Sans Condensed','Arial Narrow',serif;background:#ddd url(../images/bg.jpg) repeat top left;font-weight:400;font-size:15px;color:#333;}
a{color:#555;text-decoration:none;}
.container{width:100%;position:relative;}
.clr{clear:both;padding:0;height:0;margin:0;}
.container > header{margin:10px;padding:20px 10px 10px 10px;position:relative;display:block;text-shadow:1px 1px 1px rgba(0,0,0,0.2);text-align:center;}
.container > header h1{font-size:36px;line-height:36px;margin:0;position:relative;font-weight:300;color:#916e82;text-shadow:1px 1px 1px rgba(255,255,255,0.7);}
.container > header h1 span{font-weight:700;}
.container > header h2{font-size:14px;font-weight:300;margin:0;padding:15px 0 5px 0;color:#4d525d;font-family:Cambria,Georgia,serif;font-style:italic;text-shadow:1px 1px 1px rgba(255,255,255,0.9);}
/* Header Style */
.codrops-top{line-height:24px;font-size:11px;background:#fff;background:rgba(255,255,255,0.6);text-transform:uppercase;z-index:9999;position:relative;font-family:Cambria,Georgia,serif;box-shadow:1px 0px 2px rgba(0,0,0,0.2);}
.codrops-top a{padding:0px 10px;letter-spacing:1px;color:#333;display:inline-block;}
.codrops-top a:hover{background:rgba(255,255,255,0.3);}
.codrops-top span.right{float:right;}
.codrops-top span.right a{float:left;display:block;}
.support-note span{color:#ac375d;font-size:16px;display:none;font-weight:bold;text-align:center;padding:5px 0;}
.no-cssanimations .support-note span.no-cssanimations,.no-csstransforms .support-note span.no-csstransforms,.no-csstransforms3d .support-note span.no-csstransforms3d,.no-csstransitions .support-note span.no-csstransitions{display:block;}
CSS代码(normalize.css):
/*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */
/* ============================================================================= HTML5 display definitions ========================================================================== */
/* * Corrects block display not defined in IE6/7/8/9 & FF3 */
article,aside,details,figcaption,figure,footer,header,hgroup,nav,section,summary{display:block;}
/* * Corrects inline-block display not defined in IE6/7/8/9 & FF3 */
audio,canvas,video{display:inline-block;*display:inline;*zoom:1;}
/* * Prevents modern browsers from displaying 'audio' without controls * Remove excess height in iOS5 devices */
audio:not([controls]){display:none;height:0;}
/* * Addresses styling for 'hidden' attribute not present in IE7/8/9,FF3,S4 * Known issue:no IE6 support */
[hidden]{display:none;}
/* ============================================================================= Base ========================================================================== */
/* * 1. Corrects text resizing oddly in IE6/7 when body font-size is set using em units * http://clagnut.com/blog/348/#c790 * 2. Prevents iOS text size adjust after orientation change,without disabling user zoom * www.456bereastreet.com/archive/201012/controlling_text_size_in_safari_for_ios_without_disabling_user_zoom/ */
html{font-size:100%;/* 1 */
-webkit-text-size-adjust:100%;/* 2 */
-ms-text-size-adjust:100%;/* 2 */
}
/* * Addresses font-family inconsistency between 'textarea' and other form elements. */
html,button,input,select,textarea{font-family:sans-serif;}
/* * Addresses margins handled incorrectly in IE6/7 */
body{margin:0;}
/* ============================================================================= Links ========================================================================== */
/* * Addresses outline displayed oddly in Chrome */
a:focus{outline:thin dotted;}
/* * Improves readability when focused and also mouse hovered in all browsers * people.opera.com/patrickl/experiments/keyboard/test */
a:hover,a:active{outline:0;}
/* ============================================================================= Typography ========================================================================== */
/* * Addresses font sizes and margins set differently in IE6/7 * Addresses font sizes within 'section' and 'article' in FF4+,Chrome,S5 */
h1{font-size:2em;margin:0.67em 0;}
h2{font-size:1.5em;margin:0.83em 0;}
h3{font-size:1.17em;margin:1em 0;}
h4{font-size:1em;margin:1.33em 0;}
h5{font-size:0.83em;margin:1.67em 0;}
h6{font-size:0.75em;margin:2.33em 0;}
/* * Addresses styling not present in IE7/8/9,S5,Chrome */
abbr[title]{border-bottom:1px dotted;}
/* * Addresses style set to 'bolder' in FF3+,S4/5,Chrome*/
b,strong{font-weight:bold;}
blockquote{margin:1em 40px;}
/* * Addresses styling not present in S5,Chrome */
dfn{font-style:italic;}
/* * Addresses styling not present in IE6/7/8/9 */
mark{background:#ff0;color:#000;}
/* * Addresses margins set differently in IE6/7 */
p,pre{margin:1em 0;}
/* * Corrects font family set oddly in IE6,S4/5,Chrome * en.wikipedia.org/wiki/User:Davidgothberg/Test59 */
pre,code,kbd,samp{font-family:monospace,serif;_font-family:'courier new',monospace;font-size:1em;}
/* * Improves readability of pre-formatted text in all browsers */
pre{white-space:pre;white-space:pre-wrap;word-wrap:break-word;}
/* * 1. Addresses CSS quotes not supported in IE6/7 * 2. Addresses quote property not supported in S4 */
/* 1 */
q{quotes:none;}
/* 2 */
q:before,q:after{content:'';content:none;}
small{font-size:75%;}
/* * Prevents sub and sup affecting line-height in all browsers * gist.github.com/413930 */
sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}
sup{top:-0.5em;}
sub{bottom:-0.25em;}
/* ============================================================================= Lists ========================================================================== */
/* * Addresses margins set differently in IE6/7 */
dl,menu,ol,ul{margin:1em 0;}
dd{margin:0 0 0 40px;}
/* * Addresses paddings set differently in IE6/7 */
menu,ol,ul{padding:0 0 0 40px;}
/* * Corrects list images handled incorrectly in IE7 */
nav ul,nav ol{list-style:none;list-style-image:none;}
/* ============================================================================= Embedded content ========================================================================== */
/* * 1. Removes border when inside 'a' element in IE6/7/8/9,FF3 * 2. Improves image quality when scaled in IE7 * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ */
img{border:0;/* 1 */
-ms-interpolation-mode:bicubic;/* 2 */
}
/* * Corrects overflow displayed oddly in IE9 */
svg:not(:root){overflow:hidden;}
/* ============================================================================= Figures ========================================================================== */
/* * Addresses margin not present in IE6/7/8/9,S5,O11 */
figure{margin:0;-webkit-margin-before:0;-webkit-margin-after:0;-webkit-margin-start:0;-webkit-margin-end:0;}
/* ============================================================================= Forms ========================================================================== */
/* * Corrects margin displayed oddly in IE6/7 */
form{margin:0;}
/* * Define consistent border,margin,and padding */
fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}
/* * 1. Corrects color not being inherited in IE6/7/8/9 * 2. Corrects text not wrapping in FF3 * 3. Corrects alignment displayed oddly in IE6/7 */
legend{border:0;/* 1 */
padding:0;white-space:normal;/* 2 */
*margin-left:-7px;/* 3 */
}
/* * 1. Corrects font size not being inherited in all browsers * 2. Addresses margins set differently in IE6/7,FF3+,S5,Chrome * 3. Improves appearance and consistency in all browsers */
button,input,select,textarea{font-size:100%;/* 1 */
margin:0;/* 2 */
vertical-align:baseline;/* 3 */
*vertical-align:middle;/* 3 */
}
/* * Addresses FF3/4 setting line-height on 'input' using !important in the UA stylesheet */
button,input{line-height:normal;/* 1 */
}
/* * 1. Improves usability and consistency of cursor style between image-type 'input' and others * 2. Corrects inability to style clickable 'input' types in iOS * 3. Removes inner spacing in IE7 without affecting normal text inputs * Known issue:inner spacing remains in IE6 */
button,input[type="button"],input[type="reset"],input[type="submit"]{cursor:pointer;/* 1 */
-webkit-appearance:button;/* 2 */
*overflow:visible;/* 3 */
}
/* * Re-set default cursor for disabled elements */
button[disabled],input[disabled]{cursor:default;}
/* * 1. Addresses box sizing set to content-box in IE8/9 * 2. Removes excess padding in IE8/9 * 3. Removes excess padding in IE7 Known issue:excess padding remains in IE6 */
input[type="checkbox"],input[type="radio"]{box-sizing:border-box;/* 1 */
padding:0;/* 2 */
*height:13px;/* 3 */
*width:13px;/* 3 */
}
/* * 1. Addresses appearance set to searchfield in S5,Chrome * 2. Addresses box-sizing set to border-box in S5,Chrome (include -moz to future-proof) */
input[type="search"]{-webkit-appearance:textfield;/* 1 */
-moz-box-sizing:content-box;-webkit-box-sizing:content-box;/* 2 */
box-sizing:content-box;}
/* * Removes inner padding and search cancel button in S5,Chrome on OS X */
input[type="search"]::-webkit-search-decoration,input[type="search"]::-webkit-search-cancel-button{-webkit-appearance:none;}
/* * Removes inner padding and border in FF3+ * www.sitepen.com/blog/2008/05/14/the-devils-in-the-details-fixing-dojos-toolbar-buttons/ */
button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}
/* * 1. Removes default vertical scrollbar in IE6/7/8/9 * 2. Improves readability and alignment in all browsers */
textarea{overflow:auto;/* 1 */
vertical-align:top;/* 2 */
}
/* ============================================================================= Tables ========================================================================== */
/* * Remove most spacing between table cells */
table{border-collapse:collapse;border-spacing:0;}
CSS代码(style.css):
.ia-container{width:685px;margin:20px auto;overflow:hidden;box-shadow:1px 1px 4px rgba(0,0,0,0.08);border:7px solid rgba(255,255,255,0.6);}
.ia-container figure{position:absolute;top:0;left:50px;/* width of visible piece */
width:335px;box-shadow:0 0 0 1px rgba(255,255,255,0.6);-webkit-transition:all 0.3s ease-in-out;-moz-transition:all 0.3s ease-in-out;-o-transition:all 0.3s ease-in-out;-ms-transition:all 0.3s ease-in-out;transition:all 0.3s ease-in-out;}
.ia-container > figure{position:relative;left:0 !important;}
.ia-container img{display:block;width:100%;}
.ia-container input{position:absolute;top:0;left:0;width:50px;/* just cover visible part */
height:100%;cursor:pointer;border:0;padding:0;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:alpha(opacity=0);opacity:0;z-index:100;-webkit-appearance:none;-moz-appearance:none;appearance:none;}
.ia-container input:checked{width:5px;left:auto;right:0px;}
.ia-container input:checked ~ figure{-webkit-transition:all 0.7s ease-in-out;-moz-transition:all 0.7s ease-in-out;-o-transition:all 0.7s ease-in-out;-ms-transition:all 0.7s ease-in-out;transition:all 0.7s ease-in-out;left:335px;}
.ia-container figcaption{width:100%;height:100%;background:rgba(87,73,81,0.1);position:absolute;top:0px;-webkit-transition:all 0.2s linear;-moz-transition:all 0.2s linear;-o-transition:all 0.2s linear;-ms-transition:all 0.2s linear;transition:all 0.2s linear;}
.ia-container figcaption span{position:absolute;top:40%;margin-top:-30px;right:20px;left:20px;overflow:hidden;text-align:center;background:rgba(87,73,81,0.3);line-height:20px;font-size:18px;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";filter:alpha(opacity=0);opacity:0;text-transform:uppercase;letter-spacing:4px;font-weight:700;padding:20px;color:#fff;text-shadow:1px 1px 1px rgba(0,0,0,0.1);}
.ia-container input:checked + figcaption,.ia-container input:checked:hover + figcaption{background:rgba(87,73,81,0);}
.ia-container input:checked + figcaption span{-webkit-transition:all 0.4s ease-in-out 0.5s;-moz-transition:all 0.4s ease-in-out 0.5s;-o-transition:all 0.4s ease-in-out 0.5s;-ms-transition:all 0.4s ease-in-out 0.5s;transition:all 0.4s ease-in-out 0.5s;-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=99)";filter:alpha(opacity=99);opacity:1;top:50%;}
.ia-container #ia-selector-last:checked + figcaption span{-webkit-transition-delay:0.3s;-moz-transition-delay:0.3s;-o-transition-delay:0.3s;-ms-transition-delay:0.3s;transition-delay:0.3s;}
.ia-container input:hover + figcaption{background:rgba(87,73,81,0.03);}
.ia-container input:checked ~ figure input{z-index:1;}
@media screen and (max-width:720px){.ia-container{width:540px;}
.ia-container figure{left:40px;width:260px;}
.ia-container input{width:40px;}
.ia-container input:checked ~ figure{left:260px;}
.ia-container figcaption span{font-size:16px;}
}
@media screen and (max-width:520px){.ia-container{width:320px;}
.ia-container figure{left:20px;width:180px;}
.ia-container input{width:20px;}
.ia-container input:checked ~ figure{left:180px;}
.ia-container figcaption span{font-size:12px;letter-spacing:2px;padding:10px;margin-top:-20px;}
}