rotate3D/flipped jQuery cssHook v0.1
Elegant and simple cssHooks to perform 3D-like css rotations and control visible side.
by jrdiaz
HTML
<script src="https://raw.github.com/brandonaaron/jquery-cssHooks/master/transform.js"></script>
<div class="card"></div>
CSS
.card {
position: relative;
left: 50px;
top: 50px;
width: 200px;
height: 277px;
background-image: url(http://upload.wikimedia.org/wikipedia/en/thumb/a/aa/Magic_the_gathering-card_back.jpg/200px-Magic_the_gathering-card_back.jpg);
}
JavaScript
/**
* rotate3D/flipped jQuery cssHook v0.1
* ==========================================================
* (C) 2011 José Ramón Díaz - [email protected]
*
* Elegant and simple cssHooks to perform 3D-like css rotations and control
* visible side.
*
* REQUIRES.
* A cssHook/code make transform CSS3 property work converting human readable
* values into its transformation matrix. In my case i've used the transform
* cssHooks from Louis-Rémi Babé to make it compatible, but you are free to use
* whatever you want meanwhile makes transform work.
* https://github.com/brandonaaron/jquery-cssHooks
*
* CSS properties use the grammar:
* - "rotate3D: <n>[deg]"
* - "flipped: true|false"
*
* When an element is rotated, flipped CSS property is set according the
* element orientation. Side changes occurs on 90/270 degrees.
*
* Side change event callback can be used defining the function $.fn.flippedEvent.
* $.fn.flippedEvent = function( elem, isFlipped ) { <yourCode> };
*
* Examples:
* - elem.css('rotate3D') - Gets current rotation
* - elem.css('rotate3D', 180) - Rotates element 180 degrees
* - elem.animate({ rotate3D, -180 }, 1000); - Animates element from current rotation to -180 degrees
* - elem.animate({ rotate3D, "+=360" }, 1000); - Animates element adding 360 degrees to its current rotation
* - $('.c').animate({'rotate3D': '+=180'}, 2000, 'easeOutBounce') - Animates using easing function 'easeInOutBounce' defined in jQueryUI
*
* Browser copatibility.
* Any modern CSS3 compatible browser.
*
* NOTE: cssHooks needs jQuery v1.4.3 or greater.
*
* Inspired by zachstronaut's rotate3Di
* http://www.zachstronaut.com/projects/rotate3di/
*
* Legal stuff
* You are free to use this code, but you must give credit and/or keep header intact.
* Please, tell me if you find it useful. An email will be enough.
* If you enhance this code or correct a bug, please, tell me.
...