Link Nudge jQuery Plugin
Wednesday, August 5th, 2009
I think it was David Walsh who first showed me the idea of link nudging using jQuery. You can see on the sidebar we also use this technique. I haven't seen a plugin made to do this yet (as it is really simple) so I figured this would be perfect for a quick jQuery plugin tutorial. You can download the plugin and/or view the demo below.
View Demo
Authors Note:This plugin has now been given the name of NudgeIt and has had a lot of new features added! Please see the two updates at the bottom of this page for more information.
The Plugin Javascript
Creating the plugin is simple and is as easy as creating any other jQuery plugin. I'll try to comment the source code some so you can get an idea of how it all works.
jQuery Link Nudge Plugin
Posted by DrewDouglass on August 5th, 2009
Plugin Source.
//Define the plugin, named 'linkNudge'
$.fn.linkNudge = function(params){
//set default parameters
params = $.extend({
padding: 20,
elapseTime: 300,
returnPadding: 0}, params);
//Traverse every node passed
this.each(function(){
//Define this as a single object
var $t = $(this);
//Proceed to nudge on hover
$t.hover(function(){
$t.stop().css('cursor', 'pointer').animate({paddingLeft: params.padding}, params.elapseTime);
}, function(){
$t.stop().animate({paddingLeft: params.returnPadding}, params.elapseTime);
});
});
return this;//Allow for chaining.
};
})(jQuery);
Usage
$(function(){
$('ul li:even').linkNudge({
elapseTime: 500
}).css('list-style-type', 'circle');//Plugin allows for chaining, as seen with the css call.
});
Documentation
To use the plugin, simply include the plugin and jQuery library on your page and make a call to the linkNudge function. You can include three optional parameters, as discussed below.
- padding - Allows you to set how far the link should be nudged. Defaults to 20px.
- elapseTime - The time, in milliseconds, over which the nudge should occur. Default to 300.
- returnPadding - Optional padding to return to when the element is no longer being hovered. Defaults to 0.
Terms of Use
You can't sell it. Otherwise, use it how you would like in your projects, a credit to this page in the notes or documentation would be appreciated. Donations even more so.
View Demo
Feed Me
If you have used or enjoy this plugin, I urge you to consider making a small donation so I can buy some Chinese food.
Update:
David Walsh has modified the flexibility of the plugin in a new post on his blog. I encourage all of you to give it a look and download and see how they differ. You can find Davids plugin on his website. Thanks for adding on to and improving the plugin David!
Update Two!
David and I have decided to collaborate on this plugin and host it on a GitHub so everyone can easily keep track of any updates or changes. We are now also calling the plugin, quite appropriately, NudgeIt.
If you enjoyed this article, you might consider subscribing to our rss feed to stay updated with all the latest tips and articles!
Article Sponsored by:
Do you like teh codez? So do we, and that's why you should add us to your watchlist on Snipplr. You'll get to keep up with all of the latest code snippets and scripts that we post.
13 Comments
subscribe comments feedTrackbacks/Pingbacks
- Best jQuery Plugins/Techniques For Web Designers And Developers | guidesigner.net
- 20 jQuery Plugins/Techniques » Synergy Computer and Network Services Private Limited
- Best jQuery Plugins/Techniques For Web Designers And Developers | Web Design GroundBreak
- THAT Web Design Agency Blog | Web Design and Web Marketing» Blog Archive » jQuery THAT rocks – October 2009
- jQuery Link Nudge Plugin









Nice job plugin-izing my technique!
Thanks for being the one to bring the technique to my attention!
Nice one Drew!
Thanks Brian
thanks to writing the awesome plugin!
Sidenote….
How you have the nudge set up on your sidebar is great except for how the nudge pushes words to the next line.
Just looks bad….
Kinda like when people make links a bigger font size or bold when hovering over them in a paragraph.
I understand what you mean, and to be honest, this is just a risk or fault I am willing to take. I think the effect is worth causing a new line break every once in a while
Like i said it still a awesome plugin!
And i see David made his now and you are going to update yours as well.
Thank You Drew & David for continuing to develop this plugin/effect!
Thanks for your continued support, I appreciate it