Return to Snippet

Revision: 35007
at August 3, 2011 22:42 by claudiowebdesign


Updated Code
/*
 *  Spiral [v1.1]
 *  Distributed under the Do-wathever-the-hell-you-want-with-it License
 *
 *  Web site:	http://claudiobonifazi.com
 *  Blog:	http://claudiobonifazi.com?p=4
 *  Email:	[email protected]
 *  Twitter:	@ClaudioBonifazi
 */



/*
	Options = {
		Radius:	numeric (pixels), horizontal distance between starting and final points;
		Duration: number of milliseconds (as for animate) ;
		Easing:	the number of cicles - if it is higher than 2 it will make more turns and will assume a 'bouncing' deceleration effect
		Queue:	boolean (as for animate) ;
		Ydirection: boolean. If true, the rotation starts going up instead of down.
		Xdirection: boolean. If true the movement will be from left to the right, instead of right to left.
		InsideOut: boolean. If true, the object will whirl out from the inside of the spiral. Note that setting it to true changes the sense of Xdirection ;
	},
	Callback = function called when the animation ends (as for animate) ;
*/
(function($){
	$.fn.spiral = function( Options, Callback ){
		/*-- Input filtering --*/
		Opt= {
			Radius:		150,
			Duration:	100,
			Easing:		2,
			Queue:		false,
			Xdirection:	false,
			Ydirection:	false,
			InsideOut:	false
		}
		$.extend(Opt,Options)
		if(!Callback)
			Callback= function(){return};
		/*-- Animation starts --*/
		return this.each(function(){
			var elem=$(this),
				start_l=parseInt(elem.css('margin-left')),
				start_t=parseInt(elem.css('margin-top')),
				start_z=elem.css('z-index');
			elem
			.animate({'z-index':start_z},{
				duration: Opt.Duration,
				complete: Callback,
				step:function(now,fx){
					fgamma = Opt.InsideOut ? Opt.Radius*(1+fx.pos) : Opt.Radius*(1-fx.pos);
					gamma=fx.pos*Opt.Easing*Math.PI;
					gamma=(Opt.Ydirection) ? -gamma : gamma;
					x=(Opt.Xdirection) ? (start_l+Opt.Radius-fgamma*Math.cos(gamma))+'px' : (start_l-Opt.Radius+fgamma*Math.cos(gamma))+'px';
					y=(start_t+fgamma*Math.sin(gamma))+'px';
					$(fx.elem).css({'margin-left':x,'margin-top':y})
				},
				queue: Opt.Queue
			})
		})
	}
})(jQuery)

Revision: 35006
at November 5, 2010 06:57 by claudiowebdesign


Updated Code
/*
 *  Spiral [v1.1]
 *  Distributed under the Do-wathever-the-hell-you-want-with-it License
 *
 *  Web site:	http://www.claudiowebdesign.it/
 *  Blog:	http://www.claudiowebdesign.it/blog/
 *  Email:	[email protected]
 *  Twitter:	@ClaudioBonifazi
 */



/*
	Options = {
		Radius:	numeric (pixels), horizontal distance between starting and final points;
		Duration: number of milliseconds (as for animate) ;
		Easing:	the number of cicles - if it is higher than 2 it will make more turns and will assume a 'bouncing' deceleration effect
		Queue:	boolean (as for animate) ;
		Ydirection: boolean. If true, the rotation starts going up instead of down.
		Xdirection: boolean. If true the movement will be from left to the right, instead of right to left.
		InsideOut: boolean. If true, the object will whirl out from the inside of the spiral. Note that setting it to true changes the sense of Xdirection ;
	},
	Callback = function called when the animation ends (as for animate) ;
*/
(function($){
	$.fn.spiral = function( Options, Callback ){
		/*-- Input filtering --*/
		Opt= {
			Radius:		150,
			Duration:	100,
			Easing:		2,
			Queue:		false,
			Xdirection:	false,
			Ydirection:	false,
			InsideOut:	false
		}
		$.extend(Opt,Options)
		if(!Callback)
			Callback= function(){return};
		/*-- Animation starts --*/
		return this.each(function(){
			var elem=$(this),
				start_l=parseInt(elem.css('margin-left')),
				start_t=parseInt(elem.css('margin-top')),
				start_z=elem.css('z-index');
			elem
			.animate({'z-index':start_z},{
				duration: Opt.Duration,
				complete: Callback,
				step:function(now,fx){
					fgamma = Opt.InsideOut ? Opt.Radius*(1+fx.pos) : Opt.Radius*(1-fx.pos);
					gamma=fx.pos*Opt.Easing*Math.PI;
					gamma=(Opt.Ydirection) ? -gamma : gamma;
					x=(Opt.Xdirection) ? (start_l+Opt.Radius-fgamma*Math.cos(gamma))+'px' : (start_l-Opt.Radius+fgamma*Math.cos(gamma))+'px';
					y=(start_t+fgamma*Math.sin(gamma))+'px';
					$(fx.elem).css({'margin-left':x,'margin-top':y})
				},
				queue: Opt.Queue
			})
		})
	}
})(jQuery)

Revision: 35005
at November 1, 2010 05:03 by claudiowebdesign


Initial Code
/*
 *  Spiral [v1.1]
 *  Distributed under the Do-wathever-the-hell-you-want-with-it License
 *
 *  Web site:	http://www.claudiowebdesign.it/
 *  Blog:	http://www.claudiowebdesign.it/blog/
 *  Email:	[email protected]
 *  Twitter:	@ClaudioBonifazi
 */



/*
	Options = {
		Radius:	numeric (pixels), horizontal distance between starting and final points;
		Duration: number of milliseconds (as for animate) ;
		Easing:	the number of cicles - if it is higher than 2 it will make more turns and will assume a 'bouncing' deceleration effect
		Queue:	boolean (as for animate) ;
		Ydirection: boolean. If true, the rotation starts going up instead of down.
		Xdirection: boolean. If true the movement will be from left to the right, instead of right to left.
		InsideOut: boolean. If true, the object will whirl out from the inside of the spiral. Note that setting it to true changes the sense of Xdirection ;
	},
	Callback = function called when the animation ends (as for animate) ;
*/
(function($){
	$.fn.spiral = function( Options, Callback ){
		/*-- Input filtering --*/
		Opt= {
			Radius:		150,
			Duration:	100,
			Easing:		2,
			Queue:		false,
			Xdirection:	false,
			Ydirection:	false,
			InsideOut:	false
		}
		$.extend(Opt,Options)
		if(!Callback)
			Callback= function(){return};
		/*-- Animation starts --*/
		return this.each(function(){
			var elem=$(this),
				start_l=parseInt(elem.css('margin-left')),
				start_t=parseInt(elem.css('margin-top')),
				start_z=elem.css('z-index');
			elem
			.css({'z-index':start_z})
			.animate({'z-index':Opt.Duration+start_z},{
				duration: Opt.Duration,
				complete: Callback,
				step:function(now,fx){
					fgamma = Opt.InsideOut ? Opt.Radius*(1+fx.pos) : Opt.Radius*(1-fx.pos);
					gamma=fx.pos*Opt.Easing*Math.PI;
					gamma=(Opt.Ydirection) ? -gamma : gamma;
					x=(Opt.Xdirection) ? (start_l+Opt.Radius-fgamma*Math.cos(gamma))+'px' : (start_l-Opt.Radius+fgamma*Math.cos(gamma))+'px';
					y=(start_t+fgamma*Math.sin(gamma))+'px';
					$(fx.elem).css({'margin-left':x,'margin-top':y})
				},
				queue: Opt.Queue
			})
			.css({'z-index':start_z})
		})
	}
})(jQuery)

Initial URL
http://claudiobonifazi.com

Initial Description
A jQuery plugin that adds the .spiral() method, wich moves an element along an archimedean spiral path.

Initial Title
jQuery plugin: Spiral animations

Initial Tags
javascript, jquery

Initial Language
jQuery