开发者

Change width of element with mouseover jquery

开发者 https://www.devze.com 2022-12-29 22:57 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消