tags:

views:

23

answers:

2

I am trying to create a thin line under a nav bar to follow the mouse but am having trouble getting e.page:X to set the width of the element.

Here is what I have:

$('#test').mousemove(function(){
var linewidth = e.pageX;
$("#line").width($linewidth);
                              })
})

Can anyone tell me why this is not setting the width of #line

+1  A: 

try:

$('#test').mousemove(function(e){ // notice the e...
    var $linewidth = e.pageX; //notice also $linewidth
    $("#line").width($linewidth);
                             // I removed some extra brackets here        
})
Reigel
Does the `linewidth` variable need to be prefixed with "$"? I know that PHP variables need it, but I thought Javascript variables could be just `linewidth` alone.
Lucanos
in php `$` is required... in JS its just a valid variable... you may or may not put `$`... for me, putting `$`s in my variables would just mean it's a jQuery variable...
Reigel
A: 

This will follow the mouse across the whole page:

$('body').live('mousemove',function(e){ 
    $("#line").width( e.pageX);
});

If you are just watching '#test', you will only track the cursor when it is over that element.

ndp