// VERSION: 1.7 LAST UPDATE: 16.12.2010 /* * THIS IS FREE SCRIPT BUT LEAVE THIS COMMENT IF * YOU WANT USE THIS CODE ON YOUR SITE * * Made by Wilq32, wilq32@gmail.com, Wroclaw, Poland, 01.2009 * http://wilq32.blogspot.com * */ /* Description: This is an final product of a Wilq32.PhotoEffect Snippet. Actually you can use this simple and tiny script to get effect of rotated images directly from client side (for ex. user generated content), and animate them using own functions. Notices: Include script after including main jQuery. Whole plugin uses jQuery namespace and should be compatible with older version (unchecked). Usage: jQuery(imgElement).rotate(angleValue) jQuery(imgElement).rotate(parameters) jQuery(imgElement).rotateAnimation(parameters) jQuery(imgElement).rotateAnimation(parameters) Returns: jQueryRotateElement - !!! NOTICE !!! function return rotateElement instance to help connect events with actually created 'rotation' element. Parameters: ({angle:angleValue, [animateAngle:animateAngleValue], [easing:easingFunction], [duration:durationValue], !!! DEPRECATED !!! [maxAngle:maxAngleValue], !!! DEPRECATED !!! [minAngle:minAngleValue], [callback:callbackFunction], [animatedGif:animatedGifBoolean], [bind:[{event: function},{event:function} ] }) jQuery(imgElement).rotateAnimation Where: - angleValue - clockwise rotation given in degrees, - [animateAngleValue] - optional parameter, animate rotating into this value, - [easing] - optional parameter, function to control animation speed - supports native easing function and a jquery easing plugin, default: easeOutQuart - [duration] - optional parameter, duration of a animation - default 1000ms - [maxAngleValue] - !!! DEPRECATED !!! optional parameter, maximum angle possible for animation, - [minAngleValue] - !!! DEPRECATED !!! optional parameter, minimum angle possible for animation, - [callbackFunction] - optional function to run after animation is done - [animatedGifBoolean](boolean) - optional set to display animated gif in firefox/chrome/safari !!! this might slow down browser because it need to render image again and again to display animation, - [bind: [ {event: function}...] -optional parameter, list of events binded to newly created rotateable object Examples: $(document).ready(function() { $('#image').rotate(-25); }); $(document).ready(function() { $('#image2').rotate({angle:5}); }); $(document).ready(function() { var rot=$('#image3').rotate({maxAngle:25,minAngle:-55, duration:570, easing:$.easing.easeInOutExpo, bind: [ {"mouseover":function(){rot[0].rotateAnimation(85);}}, {"mouseout":function(){rot[0].rotateAnimation(-35);}} ] }); }); */ (function($) { var supportedCSS,styles=document.getElementsByTagName("head")[0].style,toCheck="transformProperty WebkitTransform OTransform msTransform".split(" "); //MozTransform <- firefox works slower with css!!! for (var a=0;a this._parameters.duration; if (this._parameters.callback && checkEnd){ this._parameters.callback(); } // TODO: Bug for animatedGif for static rotation ? (to test) if (checkEnd && !this._parameters.animatedGif) { clearTimeout(this._timer); } else { if (this._canvas||this._vimage||this._img) { // TODO: implement easing and speed of animation this._angle = this._parameters.easing(0, actualTime - this._animateStartTime, this._animateStartAngle, this._parameters.animateAngle - this._animateStartAngle, this._parameters.duration); //this._angle-=(this._angle-this._parameters.animateAngle)*0.1; //if (typeof this._parameters.minAngle!="undefined") this._angle=Math.max(this._angle,this._parameters.minAngle); //if (typeof this._parameters.maxAngle!="undefined") this._angle=Math.min(this._angle,this._parameters.maxAngle); this._rotate((~~(this._angle*10))/10); } var self = this; this._timer = setTimeout(function() { self._animate.call(self); }, 10); } }, _rotate : (function() { var rad = Math.PI/180; if (IE) return function(angle) { this._container.style.rotation=angle+"deg"; } else if (supportedCSS) return function(angle){ this._img.style[supportedCSS]="rotate("+angle+"deg)"; } else return function(angle) { if (!this._img.width||typeof angle!="number") return; angle=(angle%360)* rad; // clear canvas this._canvas.width = this._width+this._widthAdd; this._canvas.height = this._height+this._heightAdd; // REMEMBER: all drawings are read from backwards.. so first function is translate, then rotate, then translate, translate.. this._cnv.translate(this._widthAddHalf,this._heightAddHalf); // at least center image on screen this._cnv.translate(this._widthHalf,this._heightHalf); // we move image back to its orginal this._cnv.rotate(angle); // rotate image this._cnv.translate(-this._widthHalf,-this._heightHalf); // move image to its center, so we can rotate around its center this._cnv.scale(this._aspectW,this._aspectH); // SCALE - if needed ;) this._cnv.drawImage(this._img, 0, 0); // First - we draw image } })() } if (IE) { Wilq32.PhotoEffect.prototype.createVMLNode=(function(){ document.createStyleSheet().addRule(".rvml", "behavior:url(#default#VML)"); try { !document.namespaces.rvml && document.namespaces.add("rvml", "urn:schemas-microsoft-com:vml"); return function (tagName) { return document.createElement(''); }; } catch (e) { return function (tagName) { return document.createElement('<' + tagName + ' xmlns="urn:schemas-microsoft.com:vml" class="rvml">'); }; } })(); } })(jQuery);