October 9, 201016 yr I can't seem to get the jQuery animate function to work. Can anyone see where I've mucked up in my coding... <!DOCTYPE HTML> <html> <head> <title>jQuery Popout Menu</title> <style> </style> <script type="text/javascript" src="http://jordan-adams.co.uk/res/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('li span').hover(function() { $(this).animate({padding-left: 20px}, 500); }, function() { $(this).animate({padding-left: 0px}, 500); }); }); </script> </head> <body> <ul> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> </ul> </body> </html>
October 9, 201016 yr this works <html> <head> <title>jQuery Popout Menu</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $("a").hover(function(){ $(this).animate({ 'padding-left': '+=10px' }, "normal"); }, function(){ $(this).animate({ 'padding-left': '-=10px' }, "normal"); }); </script> </head> <body> <ul id="blah"> <li><a href="#">Foo Bar</a></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> <li><span>Foo Bar</span></li> </ul> <script type="text/javascript"> $("a").hover(function(){ $(this).animate({ 'padding-left': '+=10px' }, "normal"); }, function(){ $(this).animate({ 'padding-left': '-=10px' }, "normal"); }); </script> </body>
October 9, 201016 yr Author Thanks It was because I didn't have quotes around "padding-left." The jQuery documentation annoyingly doesn't show it like that.
Create an account or sign in to comment