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
try:
$('#test').mousemove(function(e){ // notice the e...
var $linewidth = e.pageX; //notice also $linewidth
$("#line").width($linewidth);
// I removed some extra brackets here
})
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.
精彩评论