A while back I debuted a tasteful mouseover/mouseout technique called link nudging. It started with a MooTools version and shortly thereafter a jQuery version. Just recently Drew Douglass premiered a jQuery plugin that aimed at producing the same type of effect. I’ve taken some time to put together my own version of the jQuery nudging plugin.

The jQuery JavaScript

$.fn.nudge = function(params) {
	params = $.extend({
		amount: 20,				
		duration: 300,			
		property: 'padding', 	
		direction: 'left',		
		toCallback: function() {},	
		fromCallback: function() {}	
	}, params);
	this.each(function() {
		var $t = $(this);
		var $p = params;
		var dir = $p.direction;
		var prop = $p.property + dir.substring(0,1).toUpperCase() + dir.substring(1,dir.length);
		var initialValue = $t.css(prop);
		var go = {}; go[prop] = parseInt($p.amount) + parseInt(initialValue);
		var bk = {}; bk[prop] = initialValue;
		$t.hover(function() {
					$t.stop().animate(go, $p.duration, '', $p.toCallback);
				}, function() {
					$t.stop().animate(bk, $p.duration, '', $p.fromCallback);
	return this;

$(document).ready(function() {
	$('#nudgeUs li a').nudge();
	$('#nudgeUs2 li a').nudge({
		property: 'margin',
		direction: 'left',
		amount: 30,
		duration: 400,
		toCallback: function() { $(this).css('color','#f00'); },
		fromCallback: function() { $(this).css('color','#000'); }

I’ve made Drew’s script a bit more flexible by allowing the developer to set the property and direction to animate the element to and from. This plugin also detects the animated property’s original settings so the developer doesn’t need to set it. For kicks I also allow the developer to set the animate callback in case the developer wants to do some really creative stuff. My plugin is a bit larger in size but the extra file size enhances the plugin’s worth.