tags:

views:

882

answers:

4

Im having a problem. This is my website http://keironlowe.x10hosting.com/ The red lines that move in the navigation bar is due to this code below. But its not working as intended. What I want is is is for the red lines to get longer on hover. But go back to normal size when you move the cursor away, but thats not working properly, it only works once and then you have to refresh, and it doesnt work on the home link and It gets smaller instead of longer. Help?

<script type="text/javascript" src="jQuery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
 $('div', '#nav_container').hover(function() {
    $(this).animate({width: '220px'}, 1000);      
}, function() {
    $(this).animate({width: '300px'}, 1000); 
});
});
</script>
+2  A: 

Try calling .stop() before animate:

$(document).ready(function() {
  $('div', '#nav_container').hover(function() {
    $(this).stop();
    $(this).animate({width: '220px'}, 1000);      
  }, function() {
    $(this).stop();
    $(this).animate({width: '300px'}, 1000); 
  });
});

EDIT: If you want to resize the image instead of the DIV where it is contained. Try this:

$(document).ready(function() {
     $('#nav_container div').hover(function() {
     $(this).children('img').stop().animate({width: '220px'}, 1000);      
     }, function() {
     $(this).children('img').stop().animate({width: '300px'}, 1000); 
     });
});

You may need to adjust the widths and the duration to get your desired effect.

Jose Basilio
Thats got the hover on and off issue fixed.But ive realized it resizes the DIV not the img (Nav_Line.png)it still gets smaller, needs to refresh to work more than once and home doesnt work. Anymore adivce? :)
Keiron Lowe
@Keiron - Please read my edit.
Jose Basilio
Right its working perfectly!Just for some reason, Home and About lines are different height from Portfolio and contact
Keiron Lowe
It's probably something with your master.css file
Jose Basilio
A: 

Hi there,

its easy to fix mate.

write the following in the script tag:

$(document).ready(function() {
        $('.box').hover(
          function() {
              $(this).css({ background: 'blue' });
          },
          function() {
              $(this).css({ background: 'black' });
          }
        );
    });

and write the following mark up and you should have your hover smiling at you

<div class="box"></div>
Ali
A: 

oops forgot to mention; writing multiple selectors in jquery is like

('selector1, selector2, ...')

which you have mistakenly have written like:

$('div', '#nav_container').hover(function() {....

hope this helps

Ali
You should be editing your previous answer. Not posting another answer. -1
ichiban
A: 

Thanks alot guys, info was fantastic

Keiron Lowe