views:

115

answers:

4

This is my website: http://keironlowe.x10hosting.com/

I need to know how to make the red line slowly get longer when hovering over, and slowly shrink back to normal size afterwards using javascript or jQuery.

Could someone show me something to get started in the right direction?

+1  A: 

jQuery is your best bet. The documentation has a simple example you could probably modify to fit your site: jQuery Animations

Swingley
+2  A: 

Something like this:

$('#nav_container div').hover(
    function(){$(this).find('img').animate({width:'100%'},{queue:false,duration:500});},
    function(){$(this).find('img').animate({width:'auto'},{queue:false,duration:500});}
);
Matt
A: 

You can use jQuery's animate to do something to an element, which includes a duration parameter that defines how long it should take for the animation to complete. Then there's the hover function which takes a set of functions. So this is the general idea:

$('div', '#nav_container').hover(function() {
    // this gets called on hover
    $(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds        
}, function() {
    // this gets called on mouseout
    $(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds
});

EDIT:

As far as your comment, if the code is in the <HEAD>, you need to wrap the code in document.ready:

$(document).ready(function() {
    // put the code you tried here
});
Paolo Bergantino
I cant seem to get this working.Ive got <br><script type="text/javascript" src="jQuery.js"></script><script type="text/javascript"> $('div', '#nav_container').hover(function() { $(this).animate({width: '230px'}, 10000); // }, function() { $(this).animate({width: '203px'}, 10000); });</script>
Keiron Lowe
Um, take away that <br> at the start
Keiron Lowe
Its working but ive got problems. I want to increase size when I hover over it, and when I take my cursor away it goes back to normal sizeBut the code makes it increase and then go back to normal on hover. It also only works once. I have to refresh for it to work again
Keiron Lowe
Do you have the code uploaded on the URL in your question? I'd have to see it there to be able to debug further.
Paolo Bergantino
Um yes It is now
Keiron Lowe
It also doesnt work on the home link
Keiron Lowe
Got anywhere with that problem?
Keiron Lowe
+1  A: 

This article by Jonathan Snook might help you.

Evan Meagher