2009-11-23 51 views
0

在jQuery的幫助下,我怎麼能知道div box鼠標光標的哪個邊(即border)?jQuery:光標檢測

+0

https://github.com/JDMcKinstry/jQuery.cursor – SpYk3HH 2015-10-21 18:55:02

回答

3

你必須使用的jQuery event的pageX屬性和pageY:

$("#myDiv").mousemove(e) 
{ 
    var left = (e.pageX - $(this).offset().left)/$(this).width() * 100; // 0 to 100 
    var top = (e.pageY - $(this).offset().top)/$(this).height() * 100; // 0 to 100 

    if (left > 90 && top > 90) console.log ('the mouse is in the bottom right corner '); 
}