2011-12-02 56 views

回答

6
$(document).ready(function() { 
    $("#wrapper").bind('mousemove', function(e) { 
     $("#tail").css({ 
      top: e.pageY 
     }); 
    }); 
}); 

補充:要回到起始位置:

$(document).ready(function() { 
    $("#wrapper").hover(function() { 
     $.data(this, "tail_Y", $("#tail").css("top")); 
    }, function() { 
     $("#tail").css("top", $.data(this, "tail_Y")); 
    }).bind('mousemove', function(e) { 
     $("#tail").css({ 
      top: e.pageY 
     }); 
    }); 
}); 

http://jsfiddle.net/1stein/VWEEB/

+0

好極了,有沒有辦法爲尾部彈回原來的位置?你會在鼠標移出時刪除CSS功能嗎? – uriah

+0

@uriah:是[this](http://jsfiddle.net/dzejkej/VWEEB/3/)你想要什麼? – kubetz

+0

@dzejkej是的!非常感謝你 – uriah

0

這可能幫助

$(document).bind('mousemove', function(e){ 
    $('#tail').css({ 
     top: e.pageY 
    }); 
    $('#wrapper').click(function(){  
    xyz(); 

    }); 
}); 


function xyz() 
{ 
     alert('hello'); 
} 
0

試試這個:

$("#wrapper").mouseover(function() { 
    // your function here 
    alert("mouse over red area"); 
}); 

Example fiddle here

0

你必須確保你在DOM準備好運行這段代碼:

$("#wrapper").bind('mouseenter', function(e) { 
    alert("Entered Wrapper") 
});