以下是 Tab标签360度内容翻转jquery特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Tab标签360度内容翻转jquery特效</title>
<link rel="stylesheet" type="text/css" href="css/styles.css" />
</head>
<body>
<br><br>
<div id="page">
<div id="container" class="clearfix">
<div id="flip-tabs" >
<ul id="flip-navigation" class="clearfix">
<li class="selected"><a href="#" id="tab-0" >Recent</a></li>
<li><a href="#" id="tab-1" >Popular</a></li>
<li><a href="#" id="tab-2" >Comments</a></li>
</ul>
<div id="flip-container" >
<div>
<ul class="orange">
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>Cras congue venenatis interdum</li>
<li>Nunc quis tellus at eros aliquam hendrerit nec sed mauris</li>
<li>Phasellus ut erat sapien. Suspendisse ultrices vestibulum</li>
<li>Donec nec erat neque. Curabitur orci risus,</li>
</ul>
</div>
<div>
<ul class="green">
<li>Phasellus ut erat sapien. Suspendisse ultrices vestibulum</li>
<li>Donec nec erat neque. Curabitur orci risus,</li>
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit</li>
<li>Cras congue venenatis interdum</li>
<li>Nunc quis tellus at eros aliquam hendrerit nec sed mauris</li>
</ul>
</div>
<div>
<ul class="blue">
<li>Duis laoreet elementum imperdiet. Fusce iaculis,</li>
<li>erat rutrum mollis sodales, quam arcu vehicula ipsum,</li>
<li>Curabitur porttitor nisl at mi sagittis eleifend.</li>
<li>Nam tempus pretium nisl quis pharetra. Maecenas</li>
<li>at feugiat nibh sem ut urna. Curabitur turpis nisl.</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.quickflip.js" ></script>
<script type="text/javascript" >
$('document').ready(function(){
$('#flip-container').quickFlip();
$('#flip-navigation li a').each(function(){
$(this).click(function(){
$('#flip-navigation li').each(function(){
$(this).removeClass('selected');
});
$(this).parent().addClass('selected');
var flipid=$(this).attr('id').substr(4);
$('#flip-container').quickFlipper({ }, flipid, 1);
return false;
});
});
});
</script>
</body>
</html>
JS代码(jquery.quickflip.js):
/** * jQuery QuickFlip v2.0 * http://jonraasch.com/blog/quickflip-2-jquery-plugin * * Copyright (c) 2009 Jon Raasch (http://jonraasch.com/) * Licensed under the FreeBSD License (See terms below) * * @author Jon Raasch * * @projectDescription jQuery plugin to create a flipping effect * * @version 2.0.0 * * @requires jquery.js (tested with v 1.3.2) * * * TERMS OF USE - jQuery Scrolling Parallax * Open source under the FreeBSD License. * * Redistribution and use in source and binary forms,with or without modification,are permitted provided that the following conditions are met:* * 1. Redistributions of source code must retain the above copyright notice,this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice,this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY JON RAASCH 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,INCLUDING,BUT NOT LIMITED TO,THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JON RAASCH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,INDIRECT,INCIDENTAL,SPECIAL,EXEMPLARY,OR CONSEQUENTIAL DAMAGES (INCLUDING,BUT NOT LIMITED TO,PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE,DATA,OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,WHETHER IN CONTRACT,STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies,either expressed or implied,of Jon Raasch,who is the man. * * * FOR USAGE INSTRUCTIONS SEE THE DOCUMENATION AT:http://dev.jonraasch.com/quickflip/docs * * */
( function( $ ){
$.quickFlip ={
wrappers:[],options:[],objs:[],init:function( options,box ){
var options = options ||{
}
;
options.closeSpeed = options.closeSpeed || 180;
options.openSpeed = options.openSpeed || 120;
options.ctaSelector = options.ctaSelector || '.quickFlipCta';
options.refresh = options.refresh || false;
options.easing = options.easing || 'swing';
var $box = typeof( box ) != 'undefined' ? $(box):$('.quickFlip');
var $kids = $box.children();
// define $box css if ( $box.css('position') == 'static' ) $box.css('position','relative');
// define this index var i = $.quickFlip.wrappers.length;
// close all but first panel before calculating dimensions $kids.each(function(j){
var $this = $(this);
// attach standard click handler if ( options.ctaSelector ) $.quickFlip.attachHandlers($(options.ctaSelector,$this),i,j);
if ( j ) $this.hide();
}
);
$.quickFlip.options.push( options );
$.quickFlip.objs.push({
$box:$($box),$kids:$($kids)}
);
$.quickFlip.buildQuickFlip(i);
// quickFlip set up again on window resize $(window).resize( function(){
for ( var i = 0;
i < $.quickFlip.wrappers.length;
i++ ){
$.quickFlip.removeFlipDivs(i);
$.quickFlip.buildQuickFlip(i);
}
}
);
}
,buildQuickFlip:function(i,currPanel){
// get box width and height $.quickFlip.options[i].panelWidth = $.quickFlip.options[i].panelWidth || $.quickFlip.objs[i].$box.width();
$.quickFlip.options[i].panelHeight = $.quickFlip.options[i].panelHeight || $.quickFlip.objs[i].$box.height();
// init quickFlip,gathering info and building necessary objects var options = $.quickFlip.options[i];
var thisFlip ={
wrapper:$.quickFlip.objs[i].$box,index:i,halfwidth:parseInt( options.panelWidth / 2),classNames:[],panels:[],flipDivs:[],flipDivCols:[],currPanel:currPanel || 0,options:options}
;
// define each panel $.quickFlip.objs[i].$kids.each(function(j){
var $thisPanel = addPanelCss( $(this) );
thisFlip.panels.push( $thisPanel );
thisFlip.classNames.push( $thisPanel[0].className );
// build flipDivs var $flipDivs = buildFlip( thisFlip,j ).hide().appendTo(thisFlip.wrapper);
thisFlip.flipDivs.push( $flipDivs );
thisFlip.flipDivCols.push( $flipDivs.children() );
}
);
$.quickFlip.wrappers[i] = thisFlip;
function buildFlip( x,y ){
var $out = $('<div></div>');
var inner = x.panels[y].html();
var $leftCol = $(buildFlipCol(x,x.classNames[y],inner)).appendTo( $out );
var $rightCol = $(buildFlipCol(x,x.classNames[y],inner)).appendTo( $out );
$leftCol.css('right',x.halfwidth);
$rightCol.css('left',x.halfwidth);
$rightCol.children().css({
right:0,left:'auto'}
);
return $out;
}
// builds one column of the flip divs (left or right side) function buildFlipCol(x,classNames,inner ){
var $col = $('<div></div>');
$col.css({
width:x.halfwidth,height:options.panelHeight,position:'absolute',top:0,overflow:'hidden',margin:0,padding:0}
);
var $inner = addPanelCss('<div></div>');
$inner.addClass(classNames);
$inner.html(inner);
$col.html($inner);
return $col;
}
// add css for inner panel function addPanelCss( $panel ){
if ( typeof( $panel.css ) == 'undefined' ) $panel = $( $panel );
$panel.css({
position:'absolute',top:0,left:0,margin:0,padding:0,width:options.panelWidth,height:options.panelHeight}
);
return $panel;
}
}
,// function flip ( i is quickflip index,j is index of currently open panel) flip:function( i,nextPanel,repeater,options){
if ( typeof(i) != 'number' || typeof($.quickFlip.wrappers[i]) == 'undefined' ) return false;
var x = $.quickFlip.wrappers[i];
var j = x.currPanel;
var k = ( typeof(nextPanel) != 'undefined' && nextPanel != null ) ? nextPanel:( x.panels.length > j + 1 ) ? j + 1:0;
x.currPanel = k;
var repeater = typeof(repeater) != 'undefined' ? repeater:1;
var options = $.quickFlip.combineOptions( options,$.quickFlip.options[i] );
x.panels[j].hide() // if refresh set,remove flipDivs and rebuild if ( options.refresh ){
$.quickFlip.removeFlipDivs(i);
$.quickFlip.buildQuickFlip(i,k);
x = $.quickFlip.wrappers[i];
}
x.flipDivs[j].show();
// these are due to multiple animations needing a callback var panelFlipCount1 = 0;
var panelFlipCount2 = 0;
x.flipDivCols[j].animate({
width:0}
,options.closeSpeed,options.easing,function(){
if ( !panelFlipCount1 ){
panelFlipCount1++;
}
else{
x.flipDivs[k].show();
x.flipDivCols[k].css( 'width',0 );
x.flipDivCols[k].animate({
width:x.halfwidth}
,options.openSpeed,options.easing,function(){
if ( !panelFlipCount2 ){
panelFlipCount2++;
}
else{
x.flipDivs[k].hide();
x.panels[k].show();
// handle any looping of the animation switch( repeater ){
case 0:case -1:$.quickFlip.flip( i,null,-1);
break;
//stop if is last flip,and attach events for msie case 1:break;
default:$.quickFlip.flip( i,null,repeater - 1);
break;
}
}
}
);
}
}
);
}
,// attach click handlers attachHandlers:function($the_cta,i,panel){
//attach flip $the_cta.click(function(ev){
ev.preventDefault();
$.quickFlip.flip(i);
}
);
}
,removeFlipDivs:function(i){
for ( var j = 0;
j < $.quickFlip.wrappers[i].flipDivs.length;
j++ ) $.quickFlip.wrappers[i].flipDivs[j].remove();
}
,compareObjs:function(obj1,obj2){
if (!obj1 || !obj2 || !obj1.length || !obj2.length || obj1.length != obj2.length) return false;
for ( var i=0;
i < obj1.length;
i++ ){
if (obj1[i]!==obj2[i]) return false;
}
return true;
}
,combineOptions:function( opts1,opts2 ){
opts1 = opts1 ||{
}
;
opts2 = opts2 ||{
}
;
for ( x in opts1 ){
opts2[x] = opts1[x];
}
return opts2;
}
}
;
$.fn.quickFlip = function( options ){
this.each( function(){
new $.quickFlip.init( options,this );
}
);
return this;
}
;
$.fn.whichQuickFlip = function(){
var out = null;
for ( var i=0;
i < $.quickFlip.wrappers.length;
i++ ){
if ( $.quickFlip.compareObjs(this,$( $.quickFlip.wrappers[i].wrapper)) ) out = i;
}
return out;
}
;
$.fn.quickFlipper = function( options,nextPanel,repeater ){
this.each( function(){
var $this = $(this);
var thisIndex = $this.whichQuickFlip();
// if doesnt exist,set it up if ( thisIndex == null ){
$this.quickFlip( options );
thisIndex = $this.whichQuickFlip();
}
$.quickFlip.flip( thisIndex,nextPanel,repeater,options );
}
);
}
;
}
)( jQuery );
CSS代码(styles.css):
*{margin:0;padding:0;}
html,body,#page{height:100%;}
body > #page{height:auto;min-height:100%;}
#container{padding-bottom:70px;}
#footer{position:relative;margin-top:-70px;height:70px;clear:both;}
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{display:inline-block;}
* html .clearfix{height:1%;}
.clearfix{display:block;}
body{background:url('bg_vert.jpg') repeat-x;font:13px/1.3 Arial,sans-serif;color:#999;}
#page,#footer_inner{margin:0 auto;width:960px;}
h1#logo{background:url('logo.jpg') no-repeat 0 25px;overflow:hidden;height:93px;padding:25px 0;}
h1#logo a{display:block;text-indent:-9999px;height:93px;}
#container{margin:0 auto;}
.credit{text-align:center;padding:20px 0 100px;font-size:10px;}
a,a:visited{text-decoration:none;outline:none;color:#97cae6;}
a:hover{text-decoration:underline;}
#footer{background-color:#212121;}
#footer h2{font-size:18px;font-weight:normal;height:70px;line-height:70px;font-family:"微软雅黑";color:#eee;}
#footer_inner{position:relative;}
#footer a.tzine,a.tzine:visited{color:#FCFCFC;font-size:12px;line-height:70px;position:absolute;top:0;right:0;width:90px;}
/*-核心代码-*/
/* Menu style */
#flip-tabs{width:300px;margin:20px auto;position:relative;}
#flip-navigation li{display:inline;}
#flip-navigation li a{padding:10px;display:block;float:left;background:#000;color:#333;font-size:12px;margin:0 5px 0 0;}
#flip-navigation li a:hover{background:#999;color:#f0f0f0;}
#flip-navigation li.selected a{background:#999;color:#f0f0f0;}
#flip-container{width:300px;font-family:Arial;font-size:13px;}
#flip-container div{background:#fff;}
#flip-container div ul{background:#f9f9f9;border:1px solid #f0f0f0;margin:0;padding:15px 5px;list-style-position:inside;}
#flip-container div ul li{padding:5px 0;list-style:none;}