Using .animate() in jQuery
jQuery FTW. It’s easy to use, functional, and well documented. I could go on for days, jQuery is my favourite framework. Let’s see if we could create a simple navigation bar with only HTML, CSS and jQuery.
First we need to load jQuery, referring to it’s Google URL.
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js
We’re now making sure that when the nav is hovered over, it’s margin changes, at a rate of 400 milliseconds:
$(document).ready(function(){ $("nav ul li a").hover(function () { $(this).stop().animate({ 'margin-top' : "10px" },400); }); });