- Overview
- Documents
jQuery Rotate is a simple plugin to allow you to rotate images (any angle) directly on client side, and animate them using own functions. Main focus is to unify this behavior across different browsers.
Supported Browsers
- Internet Explorer 6.0 >
- Firefox 2.0 >
- Safari 3 >
- Opera 9 >
- Google Chrome
Source: code.google.com
1. INCLUDE JS FILES
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript" src="http://jqueryrotate.googlecode.com/svn/trunk/jQueryRotate.js"></script>
2. HTML
<img src="https://www.google.com/images/srpr/logo3w.png" id="image">
3. JAVASCRIPT
$("#image").rotate(45);
4. OPTIONS
$("#img").rotate(45);
[Object] Object containing parameters for rotation. Supported attributes:
$("#img").rotate({angle:45});
-
bind: [Object] Object containing events to bind on to a rotation object. $(this) inside events points to a rotation object - this way you can chain execution of rotations - $(this).rotate(...)
$("#img").rotate({bind:{ click: function(){ $(this).rotate({ angle: 0, animateTo:180 }) } } });
-
animateTo: [Number] - default 0 - Angle value in degrees of an rotation to be animated to from current angle value (or given angle parameter)
-
center: [Array] - An array containing two values - [X, Y]. They define a center of a rotation. Numeric and percentage values are possible ([100,100], or ["50%", "50%"]). Please use values between 0>= x <= imageWidth and 0>= y <= imageHeight (percentage between 0-100%) - this is limitation of already huge canvas area.
$("#img").rotate({bind:{ click: function(){ $(this).rotate({ angle: 0, center: ["50%", "100%"], animateTo:180 }) } } });
$("#img").rotate({bind:{ click: function(){ $(this).rotate({ duration:6000, angle: 0, animateTo:100 }) } } });
-
step: [Function] - default null - A function that will be executed on every animation step. As a first argument a current angle is given.
-
easing: [Function] - default (see below) - Easing function used to make animation look more natural. It takes five parameters (x,t,b,c,d) to support easing from http://gsgd.co.uk/sandbox/jquery/easing/ (for more details please see documentation at their website). Remember to include easing plugin before using it in jQueryRotate!
-
Default function:
function (x, t, b, c, d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }
-
Where:
- t: current time,
- b: begInnIng value,
- c: change In value,
- d: duration,
- x: unused
-
$("#img").rotate({bind:{ click: function(){ $(this).rotate({ angle: 0, animateTo:180, easing: $.easing.easeInOutElastic }) } } });
$("#img").rotate({bind:{ click: function(){ $(this).rotate({ angle: 0, animateTo:180, callback: function(){ alert(1) } }) } } });
This function simply returns current angle of rotated object.
$("#img").rotate({ angle: 45, bind: { click : function(){ alert($(this).getRotateAngle()); } } });
This function simply stops ongoing rotate animation.
$("#img").rotate({ bind: { click: function(){ $("#img").rotate({ angle: 0, animateTo: 180, duration: 6000 }); setTimeout(function(){ $("#img").stopRotate(); }, 1000); } } });